LESSON 02 · Independent capacity

Separate web and data

Give application code and stored data room to grow independently.

SYSTEM VIEW

The architecture

Diagram view
Machines—
Queries per page—
Network time—

Watch the database move to its own machine, see what that buys and costs, then choose its type.

  1. At first, the application code and its database share one machine. A visitor asks for a page, and every query the page needs stays on that machine.

    What changed

    • App and database on one machine
    • No network between code and data
  2. As demand grows, both jobs fight over the same machine. A slow report can starve page rendering of CPU, while the application’s memory use squeezes the database’s cache.

    What changed

    • Slow report starves pages of CPU
    • App memory squeezes the DB cache
  3. Move the database to its own machine. A tier is a group of machines doing one job, so there is now a web tier and a data tier, and they stop competing for CPU and memory.

    What changed

    • Database on its own machine
    • A web tier and a data tier
    • CPU and memory no longer shared
  4. Each query now travels between machines. A round trip inside one data center is very roughly 0.5 ms, so a page that makes 20 queries gains about 10 ms, and one with 500 accidental queries gains 250 ms.

    What changed

    • One network round trip per query
    • Page time grows with query count
    Queries per page
  5. The network between the tiers can fail by itself, even with both machines healthy. There are also two machines to patch and secure; managed services such as Amazon RDS take over some of that work for a fee.

    What changed

    • A network link that can fail
    • Two machines to patch and secure
  6. Web traffic can now grow without forcing a database upgrade, and database capacity can change without resizing the web tier. Each tier scales for its own workload.

    What changed

    • Traffic grows: only the web tier grows
    • Data grows: only the data tier grows
    What grows
  7. A relational database such as Postgres or MySQL is a practical default when records relate and queries need joins. Cassandra is built for very high write volumes read by a known key, but has no joins. Real queries decide, not scale alone.

    What changed

    • Related records and joins: relational
    • Writes read by a known key: Cassandra
    Data shape

Space plays · ← → step · Home resets

THE IDEA

How it works

As demand grows, move the database to its own machine. A tier is a group of machines doing one job, so you now have a web tier and a data tier. Web traffic can then grow without forcing a database upgrade, and database capacity can change without resizing the web tier. The two also stop competing: on one machine, a slow report can starve page rendering of CPU, while the application’s memory use squeezes the database’s cache.

The move has a price. Each query now crosses a network. A round trip inside one data center is very roughly 0.5 ms, so a page that makes 20 queries gains about 10 ms, while a page with 500 accidental queries gains 250 ms. The link can also fail on its own, and you now have two machines to patch and secure. Managed services such as Amazon RDS take over some of that work for a fee.

A relational database, such as Postgres or MySQL, is a practical default when records relate to each other and queries need joins, which combine rows from several tables. A document, key-value, graph, or column-oriented store may fit better when the access pattern or data model calls for it. Cassandra, for example, is built for very high write volumes read by a known key, but it has no joins. Evaluate actual queries, latency needs, and data shape before changing database types; “large scale” alone does not choose one for you.

DECISION POINT

A sensor platform stores billions of readings, always written and read by device ID and time range. Which storage model would you evaluate first?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Tier separation lets each tier scale for its own workload.
  • Choose storage from data relationships and query patterns.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

Why move the database off the web server as the app grows?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.