Information Technology Reference
In-Depth Information
A common issue is that a user's login state is stored locally by a web server but not
communicated to replicas. When the load balancer receives future requests from the same
user, if they are sent to a different replica the user will be asked to log in again. This will
repeat until the user has logged into every replica. Solutions to this problem are discussed
in Section 4.2.3 .
2.1.7 Replicated Databases
Systems that access databases should do so in a way that supports database scaling. The
most common way to scale database access in a distributed system is to create one or more
read-onlyreplicas.Themasterdatabasedoesalltransactionsthatmutate(makechangesto)
the database. Updates are then passed to the read-only replicas via bulk transfers. Services
can access the master database as normal, or if a query does not make any mutations it is
sent to a read-only replica. Most database access is read-only, so the majority of work is
off-loaded to the replicas. The replicas offer fast, though slightly out of date, access. The
master offers full-service access to the “freshest” data, though it might be slower.
Software that uses a database must be specifically engineered to support read-only rep-
licas.Ratherthanopeningaconnectiontothedatabase,twoconnectionsarecreated:acon-
nection to the database master and a connection to one of the read-only replicas. As deve-
lopers code each query, they give serious consideration to which connection it should be
sent over, trading off speed for freshness and realizing that every query sent directly to the
master “just in case” is consuming the master database's very precious resources.
It is good practice to segregate these kinds of queries even if the database does not have
any replicas and both connections go to the same server. Someday you will want to add
read-only replicas. Deciding which connection a query should use is best done when the
query is originally being invented, not months or years later. That said, if you find your-
self retrofitting a system after the fact, it may be a better use of your time to identify a few
heavy hitters that can be moved to the read-only replica, rather than examine every single
query in the source code. Alternatively, you may create a read-only replica for a specific
purpose, such as backups.
Search WWH ::




Custom Search