Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

120 | Chapter 4: Database


def expire_me
expire_cache(id)
end
end

Of course, the proper solution for you will depend on the specific needs of the appli-
cation. Keep in mind that any caching is primarily about optimization, and the old
warnings against premature optimization always apply. Optimization should always
be targeted at a specific, measured performance problem. Without specificity, you
don’t know what metric you are (or should be) measuring. Without measurement,
you don’t know when or by how much you’ve improved it.


Load Balancing and High Availability


Many applications require some form of load balancing and/or high availability.
Though these terms are often used together and they can often be obtained by the
same methods, they are fundamentally two different requirements. We define them
thus:


Load balancing
Spreading request load over several systems so as to reduce the load placed on a
single system.


High availability
Resiliency to the failure of one or several constituent components; the ability to
continue providing services without interruption despite component failure.


These are completely different things, but they are often required and/or provided
together. It is important to understand the difference between them in order to prop-
erly analyze the requirements of an application. It is possible to provide load balanc-
ing without high availability—for example, consider a group of servers presented to
the Internet via round-robin DNS. The load is distributed roughly equally over
the group of servers, but the system is certainly not highly available! If one server
goes down, DNS will still faithfully distribute requests to it, and every one inN
requests will go unanswered.


Conversely, high availability can be provided without load balancing. High availabil-
ity necessitates the use of redundant components, but nothing says that those com-
ponents must be online and in use. A common configuration is the hot spare: a
duplicate server that stays powered up but offline, continually monitoring its online
twin, ready to take over if necessary. This can actually be more economical than try-
ing to balance requests between the two servers and keep them in sync.


In this section, we review the primary load balancing and high availability solutions
for common database management systems.

Free download pdf