Think like a designer / CHAPTER 05
A practical system design template
Use one reusable outline while tailoring the depth to each product’s hardest requirement.
Builds on A repeatable interview process, Functional and non-functional requirements, Back-of-the-envelope estimation.
- Fill a design outline with concrete evidence.
- Locate acknowledgment, ownership, and consistency boundaries.
- Use the template without forcing unnecessary components.
01Use a template of questions, not components
An owner saves a private text snippet and names the readers allowed to open it. Later, the owner can remove a reader. Use this paste service to make the interview template concrete.
Assume snippets are at most 100 KB. Simultaneous live editing is outside the exercise. Work through seven outputs:
- Requirements: Specify creation, authorized reading and reader removal. State how quickly a removed reader must lose access.
- Estimates: Calculate the creates, reads and bytes that could affect storage or response time.
- API: Give the inputs and results for create, read and revoke operations, including errors and repeated requests.
- Data model: Save the text, owner, reader grants and creation-request result. A grant records which reader may open which paste.
- First design: Show how one database can save this small paste and its permissions, then trace a read.
- Deep dive: Explain a risk such as a lost creation response or two simultaneous permission edits.
- Failure review: Revoke a reader while text remains cached, lose a response and make the permission store unavailable.
An API describes what callers send and observe. A data model describes the saved records that make those operations possible. Keeping them separate prevents a list of endpoint names from hiding missing permission or retry data.
Change the example if an assumption changes:
- An anonymous public link allows readers without named-account grants. The service must still check that the paste is active and unexpired before returning its text.
- Multi-gigabyte content may justify separate file storage and upload completion handling.
- Live editing requires a collaboration and conflict-handling mechanism; storing text alone does not supply it.
02Fill the contract and trace a small baseline
First estimate the assumed creation workload:
- One hundred thousand users ×2 snippets/day =200,000 creates/day.
- Divide by 86,400 to obtain about 2.3 creates/second on average.
- Multiply 200,000 by 10 KB/snippet to obtain 2 GB/day before copies and supporting storage.
These inputs justify starting with a small design and measuring its complete queries. They do not prove one machine’s capacity.
For creation, let r9 name the owner’s intended request and p31 name the resulting paste:
- Verify the owner and validate the size and reader list.
- In a database transaction, check whether this owner’s
r9already has a saved result. - For a matching repeat, return the original
p31. Reject reuse with different text or readers. - For a new request, save the text, owner, grants and
r9result together. Enforce request-identifier uniqueness in the database so simultaneous repeats cannot create two pastes. - Commit and return
p31with its version. Reject oversized text before creating the paste.
For a read by Eli:
- Identify Eli and find
p31. - Check that the paste is active and has not expired.
- Read the paste’s saved grant for Eli and check that it still permits reading; a prior successful read or a cached text copy is not a grant.
- Return text only if those checks pass. In this example, a caller without permission receives the same not-found response as for an absent paste, so the reply does not reveal that a private paste exists.
A text cache can save a repeated content lookup, but the cached text does not prove that Eli’s grant still exists. One transactional database can keep modest text and grants together. If content later moves to a file store, represent unfinished creation explicitly because uploading the file and saving the record can fail separately.
03Deepen only where the promise needs it
Two owner devices can edit the reader list at the same time. Explain the update rather than saying “handle consistency”:
- Each device reads grant version 4 and proposes a different edit.
- An update asks the database to change the grants only if their saved version is still 4.
- The database checks that condition and saves the new grants and version 5 together.
- A later update based on 4 fails with a conflict. Its device rereads 5 and decides whether to apply a new edit; it does not silently overwrite the first.
Compare storage choices under the same requirements:
- Keeping small text and grants in one database makes all-or-nothing creation simpler.
- Moving large text or files out of that database can reduce byte-handling work, but requires pending creation, confirmation and cleanup.
- Adding a cache helps only if repeated reads save enough work and the permission policy remains enforceable.
Then test the concrete failures:
- Lose creation’s response. A repeated
r9must retrievep31. - Remove Eli’s grant while text stays cached. The next protected read must obey the agreed revocation rule.
- Race two grant edits from version 4. One must detect the changed version instead of silently overwriting it.
- Disconnect the permission store. Wait or refuse the protected read as agreed; do not infer permission from cached text.
The template is complete for the agreed scope when these operations have working steps, stated limits and checks. End with the current design, its largest unresolved risk and the evidence needed before the next change.
A private paste template becomes an executable path
Follow the numbered arrows
- Create r9 → Atomic storecommit required creation state
- Uncertain create → Atomic storelook up original result
- Eli reads p31 → Permission and statecheck before byte delivery
- Atomic store → Permission and stateread current paste and permission records
- Permission and state → Return textonly when permitted
Trace the diagram in words
- Create p31 and its retry result together.
- A later read checks Eli’s grant and paste expiry.
- Caching text changes byte cost, not the permission rule.
DRAW. CALCULATE. EXPLAIN.
Fill the template for an expiring private paste
20 minutes · guided practice
Assume 50,000 users each create four 5 KB pastes/day. Pastes expire after 24 hours and may be read only by named readers.
- Calculate daily content bytes.
- Show how creation stores one request result.
- Show the read checks, including expiry and reader removal.
- Lose the creation response and explain the repeated request.
Compare the worked solution
- Calculate 50,000 ×4 =200,000 pastes/day, then multiply by 5 KB to obtain 1 GB/day before copies and other storage.
- Verify the owner and input. In one transaction, check the owner/request identifier, then save the new paste, expiry, grants and result only if this request has not completed already. Enforce uniqueness for that request.
- Return the saved paste identifier. If the response is lost, the matching request finds and returns that same result.
- For every protected read, check the reader, paste status, expiry and required grant before returning text, including cached text.
- Deny an expired paste immediately under the read policy. Physical removal may happen later, but give that cleanup a retention rule and monitor it.
The checkboxes record your own assessment. The worked solution gives you a way to check the reasoning.
RETRIEVE BEFORE YOU REVEAL
Keep the important ideas.
Say the answer aloud, then turn the card over.
CARD 01What does the template contain?
- Agree on operations and quality targets.
- Calculate the load that affects a choice.
- Define requests and responses.
- Define saved records.
- Trace the first working design.
- Explain its hardest mechanism.
- Check failures and costs.
CARD 02How do I compare alternatives?
- Keep the requirements fixed when comparing choices.
- Count the work each choice saves.
- Name the new failure and operating work it adds.
- For small pastes, one database simplifies creation; separate file storage adds unfinished-upload handling.
CARD 03What should a private read trace show?
- Identify the reader and find the paste.
- Check active status, expiry and the saved grant that names this reader.
- Return text only when permitted.
Cached text and a known paste identifier do not replace these checks.
CHECK THE REASONING
Can you explain the choice?
Answer every question, then finish for an immediate score and an explanation for each answer. Aim for 80%, then revisit any gaps.
CLOSE THE LOOP
Explain it without the page.
Summarise the mechanism, one trade-off, and one failure mode. Then mark this chapter complete.