Sub topic 7
Draw the high-level architecture
This chapter assumes you have already written down requirements, scope, and assumptions, and that you have a rough capacity estimate and a sketch of the API and data model. It also assumes you know what a load balancer, a cache, a database, and a queue do. The goal here is to combine those inputs into one diagram that you can walk through and defend.
What the high-level design is for
The high-level design is the first picture of the whole system. It shows the main components, the arrows between them, and the path each important request takes. It is not a place for table schemas, class names, or tuning parameters. Those come later, in the deep dive.
A good high-level design does three things:
- It covers every functional requirement. Each requirement maps to at least one request path.
- It is consistent with your numbers. If the estimate says 11,574 average read queries per second (QPS) and 579 average write QPS, the design must have a plan for a read-heavy workload.
- It leaves visible places to go deeper. Someone reading it should see where the risk is.
The three inputs come from earlier steps: the requirements decide which paths must exist, the capacity estimate decides which components need to scale, and the API and data model decide what data flows along each arrow.
Start from the request path, not from the boxes
A common mistake is to draw a stack of familiar boxes (CDN, load balancer, cache, queue, database) and then look for a story that fits them. Reverse that. Pick the most important API call and follow it from the client to durable storage and back. Then do the next one.
Using the sketch API from the previous chapter, there are three core operations:
POST /v1/items
Content-Type: application/json
{"owner_id": "user:42", "body": "hello"}
GET /v1/items/{item_id}
GET /v1/users/{owner_id}/items?limit=20&cursor=abc123Two of them are reads and one is a write. Because the estimate shows reads outnumber writes by about 20 to 1, the read paths deserve the most attention. The write path still matters because it is where data becomes durable.
A baseline architecture
Start with the simplest design that meets the requirements. Add components only when a requirement or a number forces you to.
Each element earns its place:
| Component | Why it is there | What forces it |
|---|---|---|
| Load balancer | Spreads requests and removes failed servers from rotation | More than one app server, availability requirement |
| Stateless app servers | Run the API logic and can be added or removed freely | Peak QPS above what one server handles |
| Cache | Absorbs repeated reads | Read QPS far above write QPS, latency target |
| Primary database | Single place that accepts writes | Durability and consistency of writes |
| Read replicas | Serve reads that miss the cache | Read load that a single database cannot serve |
If a component has no entry in the "what forces it" column, remove it or be ready to justify it.
Walk the request paths
After drawing the boxes, trace each path in words. This step catches missing components and unclear ownership of data.
Write path: create an item
- The client sends
POST /v1/itemsto the load balancer. - The load balancer picks a healthy app server.
- The app server validates the input and generates an
item_id. - The app server writes the record to the primary database.
- The app server returns the new
item_idto the client.
Notice that the diagram does not say what happens to the cache. You have to decide. Options are to invalidate the cached list for that owner, to write through to the cache, or to do nothing and let entries expire. Each has a different effect on staleness, so record the choice as an assumption and revisit it in the trade-offs chapter.
Read path: fetch one item
- The app server checks the cache using the
item_id. - On a hit, it returns the cached value.
- On a miss, it reads from a replica, stores the result in the cache, and returns it.
Read path: list a user's items
This path is different because the result depends on many records and on ordering. The cursor in the API tells you the data model must support efficient "items after this position for this owner" queries. If your storage cannot do that, the diagram is wrong even though every box looks reasonable.
Make sizes visible in the design
A diagram without numbers invites arguments about taste. Annotate the key arrows or write the numbers beside the diagram. The estimate from the capacity step gives you these values:
DAU = 10_000_000
WRITES_PER_USER_PER_DAY = 5
READS_PER_USER_PER_DAY = 100
RECORD_BYTES = 500
SECONDS_PER_DAY = 86_400
PEAK_FACTOR = 2
write_qps = DAU * WRITES_PER_USER_PER_DAY / SECONDS_PER_DAY
read_qps = DAU * READS_PER_USER_PER_DAY / SECONDS_PER_DAY
storage_per_day_gb = DAU * WRITES_PER_USER_PER_DAY * RECORD_BYTES / 1e9
storage_per_year_tb = storage_per_day_gb * 365 / 1000
print(f"average write QPS: {write_qps:.0f}")
print(f"peak write QPS: {write_qps * PEAK_FACTOR:.0f}")
print(f"average read QPS: {read_qps:.0f}")
print(f"storage per day: {storage_per_day_gb:.1f} GB")
print(f"storage per year: {storage_per_year_tb:.1f} TB")Running it prints about 579 average write QPS, 1,157 peak write QPS, 11,574 average read QPS, 25 GB per day, and 9.1 TB per year. Use these to make decisions:
- 1,157 peak writes per second is within reach of one well-provisioned primary database, so you do not need to partition writes on day one.
- Peak reads are about 23,000 per second. A cache with a good hit rate cuts the load on replicas sharply. For example, a 90% hit rate leaves about 2,300 reads per second for the database tier.
- 9.1 TB per year fits on one large machine's disks for a while, but it is large enough that you should say when you would partition.
State these conclusions next to the diagram. "Single primary is enough for the stated load; partition when writes exceed X" is a defensible position. "We will shard" with no number is not.
When to add more components
The baseline is a starting point. Add a component when a specific requirement or number demands it, and say which one.
- Message queue. Add one when work does not need to finish before the response, such as sending notifications or building search indexes. It also helps when write bursts exceed what the database can absorb. The cost is eventual consistency and a new failure mode, because messages can be duplicated or delayed.
- Object storage and a CDN. Add them when the system serves large static files such as images or video. Databases are a poor place for large blobs, and a content delivery network (CDN) moves popular content closer to users.
- Search index. Add one when users need text search or flexible filtering that your primary store cannot do efficiently. It is usually a derived copy of the data, so you must define how it is kept up to date.
- Rate limiter. Add one when the requirements mention abuse, fairness between tenants, or protection of a shared dependency.
- Partitioned storage. Add it when the data volume or write rate exceeds one node. Hash-based partitioning is the simplest way to place a key on a shard:
import hashlib
def shard_for(key: str, shard_count: int) -> int:
digest = hashlib.md5(key.encode("utf-8")).digest()
return int.from_bytes(digest[:8], "big") % shard_count
print(shard_for("user:42", 4))
print(shard_for("user:43", 4))Changing shard_count remaps most keys, so adding a shard moves a large share of the data. That cost is why you note the partition key and the growth plan in the high-level design, even if you do not draw shards yet.
Synchronous versus asynchronous paths
For every path, decide whether the client waits for the whole job. The decision changes the diagram.
The record is durable before the client gets a response, while the search index catches up a moment later. A user who searches immediately after posting may not see the new item. If the requirements forbid that, either the design changes (write to the index synchronously) or the requirement is relaxed explicitly. Both are valid. Leaving it unspoken is the error.
Common mistakes
- Boxes without paths. If you cannot say which arrow a given request follows, the box probably does not belong.
- Stateful app servers. If sessions or uploads live on one server's memory or disk, the load balancer cannot send the next request elsewhere. Keep state in the cache, database, or object storage.
- A single point of failure left unmentioned. A lone primary database or a lone queue broker may be acceptable for now. Say so, and say what you would add (a standby, replication) to remove it.
- Components that ignore the numbers. A queue for 579 writes per second may be unnecessary. A single server for 23,000 peak reads per second is not enough.
- Over-detail too early. Choosing a specific product or tuning a cache eviction policy before the structure is agreed hides the shape of the system.
Check the diagram before moving on
Before you leave the high-level design, run through this short list:
- Does every functional requirement have a request path you can narrate?
- Does every non-functional requirement (latency, availability, consistency) have at least one component or decision that addresses it?
- Does each component trace back to a requirement or a number?
- Are the data stores and their owners clear, so that each piece of data has one source of truth?
- Have you marked the one or two places where you expect to go deeper?
The last item feeds into later chapters. Storage choices, scaling by replication and partitioning, and the deep dive all start from the places you flagged here.
Exercise
Using the estimate above (about 23,000 peak reads per second, 1,157 peak writes per second), a design has one app server, one database, and no cache. Name two problems with this design for the stated requirements, and say which component you would add first and why.
Show answer
First, one app server is a single point of failure and likely cannot serve 23,000 peak reads per second plus writes, so the design needs a load balancer and several stateless app servers. Second, all reads hit the one database, which is both a load risk and a single point of failure. Add a cache first, because reads outnumber writes by about 20 to 1, and a good hit rate (for example 90%) cuts database reads by roughly ten times with a small change to the design. Then add the load balancer with multiple app servers and read replicas for availability.
Exercise
A teammate's diagram shows a message queue between the app server and the database for every write. The estimate says 579 average writes per second. What question would you ask to decide whether the queue belongs?
Show answer
Ask which requirement forces it. A queue is justified if the client does not need to wait for the write to finish and bursts could overwhelm the database, or if other consumers need the event. At 579 average and about 1,157 peak writes per second, one primary database can usually take the load directly. A queue in front of every write also means the client may get a success response before the data is durable, and it adds duplicate and delay failure modes. Without a stated requirement, remove it from the main write path and use a queue only for follow-up work such as indexing.