High load, work with replication

Hello anyone. Let’s discuss how to make a rails could work with replications.

I think that simple practice is define in database.yml file all of database connections like :master, :replica.

After that we will run all of select sql queries on :replica and other queries (that will change data) on :master.

Suggest that we will use async replication which will read master log and run all of sql queries on :replica (each 2 min for example).


Case:
We have a blog on site. We send post request on /posts and create blog post (sql query run on :master) after this will redirect on index blog page where will displayed all posts (sql select query will run on :replica). But :replica not sync yet.

Question:
How can we display all real blog posts (without reloading page after 2 minutes :slight_smile: )?

Suggestions:
May be we need use cache (like redis or memcache) and select posts from cache.

Any ideas? If you know any books on this topic then write it please.

Thank you.

Hi @achempion gives them case you describe, it doesn’t sound to be like database replication is the answer. It sounds like the proper solution is probably to use Rails’ built in page or partial caching.

Can you provide more information about the particular problem that leads you to think database replication is the right solution?

thanks,
-Chad

@cpytel I just want to understand how to make service that be able to work with many requests

@achempion, we’ve built many highly scalable systems on rails, and I don’t believe any of the solutions we’ve used have ever involved read-only replicas. There are many built-in features of Rails that will allow you to work with lots of requests, ie. caching

The best way to scale a system is to write clean code and then address specific problems as the present themselves, avoiding premature optimization.

Do you have a specific problem we can did into that you’d like to find a solution for? Is the example of the blog page a real-scenario you are working with?

thanks,
-Chad

@cpytel Example with blog isn’t real situation. It’s my curiosity :slight_smile: I want to know more how to make scalable system but cant find any books on this topic :frowning:

I think part of the reason why there aren’t that many books is because as I described, the specific solutions are often application specific, dependent on the specific problem you are facing, and other unique factors like your hosting and deployment infrastructure.

We’re happy to work with you to identify potential scaling solutions, and maybe there is something generic we can extract out of it, for the benefit of all.

Anyway, as I mentioned, in the example you’ve described with the blog page, it sounds like Rails partial or page caching, documented here is the solution: Caching with Rails: An Overview — Ruby on Rails Guides