</> MAANG.io
system design · 301

Advanced

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/480 solved 0% complete

Section 5: One Key to Rule the Read Path - Data Modeling & Storage Choice

Executive Summary: This section turns Section 4's contract into stored data. We list the access patterns before naming a database, discover that every hot path is a single-key lookup, and design four small tables around that fact: links, links_by_owner, id_allocator and idempotency_keys. We then run the storage deliberation (single Postgres, sharded Postgres, a distributed key-value store, Redis as primary) against the 91 TB that Section 3 projected. The key-value store wins, partitioned on short_code, with an honest flip trigger back to Postgres. The section closes on the property that makes the rest of the design easy: a link row is written once and almost never changes.

The interviewer points at the API you just wrote: "Fine. What's behind it? Tables, keys, which database." The reflex answer is "Postgres and an auto-increment ID". Start instead with every way the system touches stored data, and how often.

Access Patterns First

Access pattern Triggered by Rate Shape
Get link by code Every redirect (GET /{short_code}) ≈ 116 K/s avg, ≈ 350 K/s peak (before cache) Single-key lookup
Put new link POST /v1/links ≈ 1.2 K/s avg, ≈ 3.5 K/s peak Single-key insert
Conditional put (insert-if-absent) Custom aliases (Section 11) Rare Single-key insert with a condition
List links by owner GET /v1/links?cursor=… Rare (dashboard views) Range scan within one owner
Disable link by code DELETE /v1/links/{short_code} Rare Single-key update

Read the "Shape" column. Every hot pattern is "give me the row for this one key". There are no joins, no aggregates and no cross-link queries. The only range query, listing an owner's links, is rare and allowed to lag a little.

Key Insight: Once the access patterns are written down, the storage choice mostly follows. A system whose hot path is a single-key lookup at hundreds of thousands per second, over a dataset too big for one machine, wants a database built to do exactly that, and not much else.

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.