3 Scaling databases
This chapter covers:
- Various types of storage services.
- Replicating databases.
- Aggregating events to reduce database writes.
- Normalization vs denormalization.
- Caching frequent queries in memory.
In this chapter, we discuss concepts in scaling databases, their tradeoffs, and common databases that utilize these concepts in their implementation. We consider these concepts when choosing databases for various services in our system.
3.1 Brief prelude on storage services
Storage services are stateful services. Compared to stateless services, stateful services have mechanisms to ensure consistency, and require redundancy to avoid data loss. A stateful service may choose mechanisms like Paxos for strong consistency or eventual-consistency mechanisms. These complex decisions and tradeoffs have to be made, and they depend on the various requirements like consistency, complexity, security, latency, performance. This is one reason we keep all services stateless as much as possible, and keep state only in stateful services.