Notes

Part 1 of 10

Trade-offs in data systems

Most apps today are limited by their data, not by their CPU. The hard parts are how much data there is, how fast it changes, and how to keep it correct and available when machines fail or many users act at once. We call these apps data-intensive. In a compute-intensive app, the hard part is instead splitting one huge calculation across many processors. This chapter compares four big design choices and shows what you gain and lose with each. No design is best for every case, so the real skill is asking the right questions for your own situation.

The building blocks

A typical app is glued together from a few standard parts:

PartWhat it does
DatabaseKeeps data so you can find it again later
CacheSaves the result of slow work so the next request is fast
Search indexLets users search by keyword or filter results
Stream processingReacts to each event soon after it happens
Batch processingWorks through a large pile of stored data every so often

Different teams in one company often want very different things from the same data. They rarely say these goals out loud, which leads to arguments about the "right" design. Naming the trade-offs makes those talks easier.

Frontends and backends

  • The frontend is code that runs on the user's device, such as a web page. A phone app plays the same role.
  • The backend is code on servers that answers requests, usually over HTTP, sometimes over WebSockets.
  • A frontend holds one person's data, while a backend holds everyone's, so most hard data problems live in the backend.
  • Backend app code reads and writes databases and other data infrastructure, such as caches and message queues.
  • Backend code is usually stateless: once it answers a request, it forgets it. Anything that must last is kept either on the client or in the data infrastructure.