Skip to content

Learning guide

Worked designs: from demand to durable chat

Follow capacity estimation and chat through three layers: understand the problem, construct the system, then stress and revise the decision.

Published date · Last edited: · 16 min reading · Author's judgment

More
20px

Two designs, three layers of reasoning

Use each unit as a reading packet: understand the task, construct its normal path, then change a condition. The linked reviewed chapters supply the complete mechanism explanations, original diagrams and topic-specific resource shelves. These guides add a route through that material; they do not require reading another version of each chapter.

From a user action to a capacity decision

Outcome: Derive separate request, origin and survivor budgets, then identify which assumption changes the decision.

Know first: Units, rates and visible assumptions.

Hypothetical scenario. Northwind plans a catalogue promotion. Choose 100,000 daily users and 20 reads per user per day. These are teaching assumptions, not measured traffic. The team wants a service that can lose one application server without accepting more work than the survivors can complete.

Layer 1 · Understand what the estimate counts

Begin with a successful catalogue read, not a machine count. Daily users describe people; operations describe work. A read can hit a cache, reach an origin or trigger several dependent queries. Retained storage describes new objects and their lifetime, so it cannot be derived by treating every read as a new stored record. Write the unit beside each quantity and distinguish the audience, logical operations and physical attempts. The daily average is a baseline. A selected peak factor is an explicit scenario to challenge, not evidence that a particular burst will occur.

Layer 2 · Construct the resource model

Use an HTTP API pool with an authoritative catalogue database and an optional cache. A record has a product identity, revision and response payload. A read request names the product; a successful response identifies the revision observed. Count API work and database work separately: a cache hit may save an origin query while still consuming API and network capacity. Before selecting servers, choose a representative payload, query and cache condition for testing. The budget below is deliberately hypothetical; it does not establish what any real machine can serve. The complete lesson separates payload bandwidth, retained data, queueing and survivor capacity rather than hiding them inside one throughput number.

Layer 3 · Stress the assumption and revise the decision

A normal cache hit ratio is not an origin availability guarantee. A cold restart can expose the origin to the full logical read stream, and retries can add attempts. Losing a server changes the remaining capacity; a concentrated tenant can invalidate a balanced-load assumption. Preserve the user action, change one condition and recompute the affected component. If the remaining origin budget is too small, bound admission or warm the cache under a controlled policy before allowing normal traffic. Adding API servers alone cannot repair a saturated database. A useful decision identifies the limiting resource and the next measurement that could falsify it.

From a user action to a capacity decision: normal requestClient names a product. Then: API authenticates and checks cache policy. Then: A miss queries the catalogue index. Then: The API returns one identified revision1. Client names a product2. API authenticates and checks cache policy3. A miss queries the catalogue index4. The API returns one identified revision
The normal path; the full chapters open the records, component boundaries and recovery paths.
Text alternative: normal request steps
  1. Client names a product
  2. API authenticates and checks cache policy
  3. A miss queries the catalogue index
  4. The API returns one identified revision

Work the numbers, keeping the units

  1. Daily reads = 100,000 users × 20 reads/user = 2,000,000 reads/day.
  2. Average = 2,000,000 / 86,400 = approximately 23.148 reads/s. Selected 5× peak = approximately 115.741 reads/s.
  3. Choose a hypothetical tested API budget of 80 reads/s per server. Two servers leave one survivor: 80 < 115.741. Three leave two: 2 × 80 = 160 > 115.741 reads/s.
  4. At an assumed 90% cache hit ratio, origin demand is approximately 11.574 reads/s. With a cold cache it is approximately 115.741 reads/s, before retries. Neither result establishes the database's own tested budget.

In the wild: Amazon's account of load shedding. Amazon describes why connection limits alone were too imprecise and discusses rejecting excess work. It does not validate Northwind's selected numbers.

Check the changed condition

Is three servers a production sizing recommendation?

No. It is the result of the chosen workload, peak, distribution and hypothetical per-server budget. Measure the same operation under representative conditions and inspect dependent resources before using it.

The cache hit ratio drops from 90% to zero. Which budget changes?

Origin demand rises from about 11.574 to 115.741 reads/s in this model. API logical demand is unchanged; retained storage does not increase merely because reads miss. Retries would be a separate attempt budget.

Could a short burst still fail while its daily average fits?

Yes. A daily average hides the arrival window. Derive the burst rate, bound queue occupancy and compare waiting with the user deadline. Do not assume an average can be served uniformly over the day.

Decision log

Size each resource from the operation that consumes it.

Use survivor capacity under explicit assumptions.

Revisit the decision when arrivals, payloads, cache behavior or measured budgets change.

Next: Apply a workload model to durable chat →

From sending a message to recovering its history

Outcome: Trace durable acceptance, live delivery and reconnect as separate observations of one conversation history.

Know first: Queues, streams and publish/subscribe.

Hypothetical scenario. Northwind is designing private conversation messaging. Choose 200,000 connected devices. A sender needs to know whether a message was durably accepted, while a returning device needs to find messages it missed. A live connection alone answers neither question.

Layer 1 · Understand what each acknowledgement means

Separate acceptance into conversation history, delivery to a device and an explicit read receipt. A successful socket write is a transport observation, not evidence that a particular application record survived failure. Choose the user promise before selecting a broker. A client supplies a stable message identity so that retrying after a lost response can find the existing accepted operation. A conversation needs a defined ordering rule; a display timestamp alone does not establish a unique durable sequence. The baseline lesson explains these observations before introducing the mechanisms that carry them.

Layer 2 · Construct a durable history and a live path

Use a gateway for connected devices and an application service owning the conversation history. A message record names the conversation, stable client message identity, sender, accepted sequence and payload. A membership record determines which user may act on that conversation. A device cursor identifies its recovery position. The send operation checks membership, durably records one accepted message under the chosen duplicate policy and returns its identity and sequence. Live fan-out then offers that accepted message to connected recipients. A gateway restart may interrupt delivery without erasing the history. These responsibilities do not require a separate service for every box; choose deployment boundaries after the transaction and capacity boundaries are understood.

Layer 3 · Stress the handoff between recovery and live delivery

On reconnect, recheck current membership before returning history. Catch up from the cursor under a defined upper boundary, then connect that boundary to live events so that messages cannot disappear in a gap between the two paths. If the paths overlap, deduplicate by accepted identity rather than inventing a second message. A revoked member's old cursor is not permission to continue reading. Pace recovery separately from normal sends: a reconnect storm can exhaust metadata or history-read budgets even when the message-write rate is unchanged. Reconcile an uncertain send against the authoritative record instead of guessing from a socket timeout.

From sending a message to recovering its history: normal requestSender chooses a stable message identity. Then: Service checks membership and appends history. Then: Acceptance returns identity and sequence. Then: Gateways deliver; reconnect reads from a cursor1. Sender chooses a stable message identity2. Service checks membership and appends history3. Acceptance returns identity and sequence4. Gateways deliver; reconnect reads from a cursor
The normal path; the full chapters open the records, component boundaries and recovery paths.
Text alternative: normal request steps
  1. Sender chooses a stable message identity
  2. Service checks membership and appends history
  3. Acceptance returns identity and sequence
  4. Gateways deliver; reconnect reads from a cursor

Work the numbers, keeping the units

  1. Hypothetical steady send model: 200,000 devices × 1 message/device/minute / 60 = approximately 3,333.333 accepted messages/s.
  2. Choose four recipient-device deliveries per accepted message: 3,333.333 × 4 = approximately 13,333.333 delivery attempts/s, before retries. This counts recipient devices, not necessarily distinct people.
  3. Suppose 20,000 devices reconnect and each needs 150 messages, fetched in pages of 50. Each device needs 150 / 50 = 3 pages; the recovery workload is 20,000 × 3 = 60,000 page requests.
  4. At a selected recovery budget of 500 completed pages/s, 60,000 / 500 = 120 seconds to drain this fixed workload, ignoring new recovery arrivals and unequal page costs. This is a simplified estimate, not a recovery SLO or measured throughput.

In the wild: Slack's Flannel account. Slack describes the cost of startup snapshots and reconnection storms, then introduces demand-driven loading. Its reported system is a real example; Northwind's workload and protocol choices above remain hypothetical.

Check the changed condition

The gateway crashes after durable append but before replying. Should the sender create another identity?

No. Retry with the original identity and reconcile against accepted history under the declared duplicate policy. A new identity would describe another message and could repeat the visible effect.

A returning device has a valid old cursor but its user was removed. May it catch up?

The cursor describes a position, not authority. Recheck current membership before returning messages or attachment data, and apply the product's defined revocation policy.

Can normal message capacity prove the reconnect storm is safe?

No. Sends, fan-out, metadata and paged history are different work. The simplified recovery calculation exposes a separate page budget; concurrent arrivals, payloads and admission policy must also be bounded.

Decision log

Acknowledge the defined durable acceptance boundary.

Recover from identified history under current membership.

Revisit gateway and storage budgets when fan-out or reconnect behavior changes.

Next: Try the chat challenge before revealing its review →

Additional worked example: document sharing

Begin with the promise

Hypothetical scenario: Northwind wants private document sharing for teams. An owner uploads a document, grants named team members access, and revokes access later. Readers fetch current metadata and download an immutable version. The first version excludes collaborative editing, public discovery and document search. Those exclusions matter: there is no reason to introduce an editing sequencer, a global search index or a public recommendation pipeline. The initial success contract is that committed metadata describes a complete verified blob, and every new download authorization checks the applicable access policy.

Separate metadata from bytes

A document record contains tenant identity, document identity, owner, selected version and lifecycle state. A version record contains its content checksum, storage object key, byte length and publication state. Membership/grant records represent access. Blob bytes live in object storage; metadata and grants live behind an application transaction boundary. A download location is not itself the record of ownership. The design must explain who can mint that location and how long a previously issued capability remains usable after revocation.

State a hypothetical workload

Choose 20,000 daily active users, ten metadata reads and one upload per active user per day. These are exercise assumptions, not observed customer traffic. Metadata reads are 20,000 × 10 = 200,000/day; average is 200,000 / 86,400 ≈ 2.315 reads/s. A chosen 10× peak is about 23.15 reads/s. Uploads average 20,000 / 86,400 ≈ 0.2315/s and peak at about 2.315/s under the same chosen multiplier. Different user behavior could make those peaks occur at different times, so a real capacity review would measure them separately.

Estimate the resource that matters

Choose 5 MB per uploaded document in decimal units. New raw bytes are 20,000 × 5 MB = 100,000 MB/day, or 100 GB/day. Thirty days of retained new versions are 3 TB before redundancy, deleted-version retention and backups. At the chosen peak, inbound bytes are approximately 2.315 × 5 MB = 11.575 MB/s. Those numbers suggest that transferring blobs through a small application process may be wasteful even though metadata request rates are modest. Let the authenticated client upload through a constrained object-storage capability rather than forcing the API worker to proxy every byte.

Choose the first architecture

Use one application deployment backed by a transactional metadata store and object storage. The application authenticates users, checks tenant-scoped grants and creates limited upload/download capabilities. A worker verifies completed uploads and publishes eligible versions. There is no immediate need for a fleet of independently deployed services. The first scalability decision separates the byte-transfer path from the metadata path because their work units differ. Horizontal API replication comes later when measured service demand, availability requirements or deployment needs justify it.

Trace the upload

First, the application authorizes an upload and creates a pending version with a stable upload identity. Second, the client transfers bytes to the constrained object key. Third, completion triggers verification of expected length, checksum and required content policy. Fourth, a guarded metadata transaction publishes the verified version and updates the document pointer. Fifth, any downstream notification/search obligation is durably represented if that feature is later added. A successful transfer alone does not mean a document is published. Retrying completion must resolve the same version rather than creating multiple independently visible versions.

Trace the download and revocation

The reader requests the document under trusted tenant context. The application checks the current grant and published-version pointer, then issues the permitted short-lived capability for that version. The blob service transfers bytes. Revoking a grant stops new authorizations after the chosen consistency boundary; it cannot recall bytes already downloaded. A still-valid capability may remain usable until expiry unless the delivery layer supports and enforces stronger revocation. State that limitation to product before promising instant global removal.

Design recovery before adding replicas

If the client disappears after upload, the pending record and object may remain. A cleanup worker needs a retention rule and must avoid deleting a version concurrently becoming published. If publication commits but its response is lost, a retry looks up the existing upload/version identity. If metadata references missing bytes, readers must receive an explicit unavailable/error state while reconciliation repairs the record; returning a fabricated empty document would hide corruption. Backups must cover metadata and retained blob versions coherently enough for the declared recovery objective.

Compare an alternative

Proxying bytes through the application simplifies some authorization and inspection paths and can make sense for a small deployment. Its cost is application bandwidth, worker occupancy and another failure point in every transfer. Direct constrained transfer reduces that work but introduces capability lifetime, object-completion verification and cleanup responsibilities. Choose using the workload and threat model, not a rule that signed URLs are always superior. Encrypting transport does not decide who should receive a capability or whether a downloaded copy can be revoked.

Apply a scale change

Suppose reads grow by a factor of 100 while upload rate stays fixed. Metadata peak becomes approximately 2,315 reads/s, while the upload-byte estimate remains unchanged. That is a reason to examine metadata indexes, application capacity and permitted caching rather than multiplying every subsystem by 100. Cache immutable version metadata where safe, but keep current authorization on a suitable authority path. If one tenant dominates traffic, inspect that tenant's key concentration rather than assuming average load per shard explains the bottleneck.

Review the design

Question: can a completed upload be immediately listed as downloadable? Only after the verification/publication contract is satisfied. Question: does a metadata replica guarantee recovery from accidental deletion? No; deletion can replicate and needs independent retained history or backup. Question: does a revoked member lose bytes already downloaded? No; the service can stop future authorized transfers under its contract but cannot retract copies outside its control. These answers expose the boundaries of the design instead of disguising them behind more components.

Decision log

Keep metadata and grants transactional because publication and access decisions require a clear authority. Separate blob transfer because bytes dominate this workload. Revisit capabilities, caching and partitioning when measured demand or the required revocation/recovery promise changes.