Force database read to master if slave data is stale
Posted
by
Jeff Storey
on Server Fault
See other posts from Server Fault
or by Jeff Storey
Published on 2012-03-22T04:03:47Z
Indexed on
2012/03/22
5:32 UTC
Read the original article
Hit count: 545
I previously asked a specific question about this database replication for new user signup to which I got an answer, but I want to ask this in the more general sense.
I have a database setup in which I am using a master/slave combination. I am using the slaves for load balancing (the data itself is partitioned/sharded across multiple databases, but each database has X slaves for load balancing).
Let's say I write some data to the master. Now I do a subsequent read which hits a slave, but the slave has not yet caught up to the master. Is there a way (which can be done quickly since it will happen frequently) to determine if the data is stale in the slave so I can then route to the master?
In my previous question, it was suggested to do simultaneous writes to the cache and the database. This solution seems practical, but there is still a chance that the data may have been removed from the cache but not yet updated in the slave.
A possible solution is to ensure the cache is big enough (based on the typical application load) so the data will not be evicted within the time frame it takes to replicate the data. This seems like it may be feasible.
Can anyone provide additional insight into this question? Thanks!
© Server Fault or respective owner