<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mseada</title>
    <description>The latest articles on DEV Community by mseada (@mseada).</description>
    <link>https://dev.to/mseada</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F591919%2F7d3412df-ee51-4627-ac3b-9845a4fae750.png</url>
      <title>DEV Community: mseada</title>
      <link>https://dev.to/mseada</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mseada"/>
    <language>en</language>
    <item>
      <title>System design capstone and final assessment</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 16:33:14 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-capstone-and-final-assessment-6jh</link>
      <guid>https://dev.to/mseada/system-design-capstone-and-final-assessment-6jh</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 8 of 8 · week 8 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The capstone has each team design a new system from a one-line brief, using the same six steps as the case studies, and the final assessment checks that everyone can apply the ideas to fresh scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Capstone brief.&lt;/strong&gt; Pick one, or have the trainer assign it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A photo sharing feed for 50 million daily users.&lt;/li&gt;
&lt;li&gt;A ride-hailing service that matches riders to nearby drivers.&lt;/li&gt;
&lt;li&gt;A file sync service like a cloud drive.&lt;/li&gt;
&lt;li&gt;A notification service that sends push, email and SMS at scale.&lt;/li&gt;
&lt;li&gt;A distributed rate limiter used by many services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Deliverables:&lt;/strong&gt; a design document of up to four pages following the six steps, one architecture diagram with numbered steps, and a 15-minute presentation followed by 10 minutes of questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pacing for a 45-minute design interview or review&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Minutes&lt;/th&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Clarify requirements and scope&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Estimate load and storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Define the API and data model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Draw the high-level design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;Deep dive on the two or three hardest parts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Trade-offs, failures and monitoring&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Common mistakes:&lt;/strong&gt; skipping requirements, designing without numbers, leaving a single point of failure, ignoring duplicates and retries, forgetting how it will be monitored, and choosing exotic technology without a reason.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Capstone rubric (100 points, pass mark 70)&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Criterion&lt;/th&gt;
&lt;th&gt;Points&lt;/th&gt;
&lt;th&gt;What good looks like&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requirements and scope&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;Functional and non-functional needs are explicit, with scope limits stated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Estimation&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;Numbers are reasonable, shown, and used to drive choices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Architecture and data model&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;A clear diagram, sensible components, API and data model that fit the requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deep dives&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;Consistency, scaling and failure handling are worked through for the hardest parts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Trade-offs and operations&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;Alternatives are weighed, and monitoring, security and cost are addressed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Final assessment&lt;/strong&gt; (12 scenario questions, pass mark 9, Architect level needs 11)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A photo app has 50 million daily users who each upload 2 photos of 3 MB a day. About how much new storage is needed per day before replication?

&lt;ul&gt;
&lt;li&gt;A) 30 TB&lt;/li&gt;
&lt;li&gt;B) 300 TB&lt;/li&gt;
&lt;li&gt;C) 3 PB&lt;/li&gt;
&lt;li&gt;D) 3 TB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Which pattern keeps a multi-service order consistent without a distributed transaction?

&lt;ul&gt;
&lt;li&gt;A) A saga with compensating actions&lt;/li&gt;
&lt;li&gt;B) A shared lock across services&lt;/li&gt;
&lt;li&gt;C) A bigger database&lt;/li&gt;
&lt;li&gt;D) Retrying every step forever&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A service must guarantee that a database update and the matching event are both recorded. What should it use?

&lt;ul&gt;
&lt;li&gt;A) Publish the event first, then update the database&lt;/li&gt;
&lt;li&gt;B) Update the database, then publish in a separate step&lt;/li&gt;
&lt;li&gt;C) A bigger queue&lt;/li&gt;
&lt;li&gt;D) The outbox pattern: write both in one transaction and publish from the outbox&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A chat message reaches the server twice because the client retried. How do you avoid showing it twice?

&lt;ul&gt;
&lt;li&gt;A) Compare timestamps&lt;/li&gt;
&lt;li&gt;B) Ignore all retries&lt;/li&gt;
&lt;li&gt;C) Deduplicate by a client-generated message ID&lt;/li&gt;
&lt;li&gt;D) Increase the timeout&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A new video loads slowly for its first viewers but fast for later ones. Why?

&lt;ul&gt;
&lt;li&gt;A) Disk wear&lt;/li&gt;
&lt;li&gt;B) The first request fills the edge cache from the origin and later requests hit the cache&lt;/li&gt;
&lt;li&gt;C) DNS caching&lt;/li&gt;
&lt;li&gt;D) Encoding finishes later&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Two refund requests for the same payment arrive at the same moment. What stops the system refunding more than was paid?

&lt;ul&gt;
&lt;li&gt;A) Hope they do not collide&lt;/li&gt;
&lt;li&gt;B) Separate caches&lt;/li&gt;
&lt;li&gt;C) Eventual consistency&lt;/li&gt;
&lt;li&gt;D) A transaction on a versioned or locked payment row, so the second request sees the first refund&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A user updates their profile but sees the old value on reload. What is the likely cause and fix?

&lt;ul&gt;
&lt;li&gt;A) Reading from a lagging follower; read your own writes from the leader&lt;/li&gt;
&lt;li&gt;B) A browser bug; clear cookies&lt;/li&gt;
&lt;li&gt;C) Too few indexes; add more&lt;/li&gt;
&lt;li&gt;D) Encryption; turn it off&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A table keyed by timestamp has one overloaded partition. What is the best fix?

&lt;ul&gt;
&lt;li&gt;A) Give that partition larger disks&lt;/li&gt;
&lt;li&gt;B) Add more replicas&lt;/li&gt;
&lt;li&gt;C) Hash or combine the key so current writes spread across partitions&lt;/li&gt;
&lt;li&gt;D) Delete old data&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Two services always deploy together and share a database. What is this?

&lt;ul&gt;
&lt;li&gt;A) An ideal microservices design&lt;/li&gt;
&lt;li&gt;B) A distributed monolith; merge them or redraw the boundaries&lt;/li&gt;
&lt;li&gt;C) A gateway problem&lt;/li&gt;
&lt;li&gt;D) A replica problem&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The card network times out on an authorization. What should the payment service do?

&lt;ul&gt;
&lt;li&gt;A) Mark it processing and check its status or reconcile before any retry&lt;/li&gt;
&lt;li&gt;B) Retry the authorization at once&lt;/li&gt;
&lt;li&gt;C) Tell the customer it failed and refund&lt;/li&gt;
&lt;li&gt;D) Delete the payment&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Peak traffic is 3 million requests per second. Each server can handle 5,000 per second, and you run servers at 50% of that. About how many servers are needed?

&lt;ul&gt;
&lt;li&gt;A) 600&lt;/li&gt;
&lt;li&gt;B) 300&lt;/li&gt;
&lt;li&gt;C) 2,400&lt;/li&gt;
&lt;li&gt;D) 1,200&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Events for the same order arrive out of order at a consumer. What is the best design?

&lt;ul&gt;
&lt;li&gt;A) Turn off the broker&lt;/li&gt;
&lt;li&gt;B) Add more consumers&lt;/li&gt;
&lt;li&gt;C) Key by order ID so they share a partition, and use version numbers to ignore stale events&lt;/li&gt;
&lt;li&gt;D) Make the messages smaller&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Final assessment answers
  &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;B&lt;/strong&gt; 50 million times 2 times 3 MB is 300 TB per day.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt; each server effectively handles 2,500 per second at 50% load, and 3 million divided by 2,500 is 1,200 servers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/donnemartin/system-design-primer" rel="noopener noreferrer"&gt;System Design Primer&lt;/a&gt;, with more practice problems and sample solutions for capstone ideas.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dataintensive.net/" rel="noopener noreferrer"&gt;Designing Data-Intensive Applications&lt;/a&gt;, for checking consistency and failure reasoning in deep dives.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter" rel="noopener noreferrer"&gt;Timeouts, retries, and backoff with jitter&lt;/a&gt;, for the failure-handling part of the rubric.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Designing Data-Intensive Applications by Martin Kleppmann, the main reference for Modules 3 and 4.&lt;/li&gt;
&lt;li&gt;Building Microservices by Sam Newman, for Module 2.&lt;/li&gt;
&lt;li&gt;System Design Interview by Alex Xu, for more worked designs.&lt;/li&gt;
&lt;li&gt;Site Reliability Engineering from Google, for reliability and monitoring practice.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/api/idempotent_requests" rel="noopener noreferrer"&gt;Stripe documentation on idempotent requests&lt;/a&gt; and &lt;a href="https://docs.stripe.com/webhooks" rel="noopener noreferrer"&gt;on webhooks&lt;/a&gt;, for Module 7.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The real-world figures in the case studies (message volume, hours uploaded and watched, connection counts) come from public statements and engineering write-ups and are used as inputs for exercises. Trainers should check the current numbers before each cohort.&lt;br&gt;
``&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>career</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System design case study: Stripe and payment systems</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 16:32:48 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-case-study-stripe-and-payment-systems-5925</link>
      <guid>https://dev.to/mseada/system-design-case-study-stripe-and-payment-systems-5925</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 7 of 8 · week 7 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In a payment system the hard problem is correctness, not scale: never charge twice, never lose a record, and always be able to prove where every cent went.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Design idempotent APIs and a payment state machine.&lt;/li&gt;
&lt;li&gt;Explain double-entry ledgers, reconciliation and why timeouts are unknown outcomes.&lt;/li&gt;
&lt;li&gt;Design reliable, signed webhooks and keep card data out of most of the system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Functional:&lt;/strong&gt; create and confirm payments, authorize then capture, refunds, support for cards and wallets, extra authentication steps such as 3D Secure, webhooks to merchants, payouts to merchant bank accounts, fraud checks and reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-functional:&lt;/strong&gt; exactly-once effect on money, strong consistency for balances, durability, a full audit trail, high availability, low latency for checkout, and compliance with card data security rules (PCI DSS).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Estimates.&lt;/strong&gt; Assume 100 million payments a day; the aim is to show that correctness is harder than volume.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quantity&lt;/th&gt;
&lt;th&gt;Calculation&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Average payments per second&lt;/td&gt;
&lt;td&gt;100 million divided by 86,400&lt;/td&gt;
&lt;td&gt;about 1,200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peak at 3 times average&lt;/td&gt;
&lt;td&gt;1,200 times 3&lt;/td&gt;
&lt;td&gt;about 3,500; a shopping holiday can reach several times that&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ledger and event storage at about 5 KB per payment&lt;/td&gt;
&lt;td&gt;100 million times 5 KB&lt;/td&gt;
&lt;td&gt;about 500 GB per day, about 180 TB per year&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Webhook events at 3 per payment&lt;/td&gt;
&lt;td&gt;300 million per day&lt;/td&gt;
&lt;td&gt;about 3,500 per second, plus retries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Downtime budget at 99.99%&lt;/td&gt;
&lt;td&gt;per year&lt;/td&gt;
&lt;td&gt;about 53 minutes, each minute costs merchants sales&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. API and data model&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;API:&lt;/strong&gt; create a payment with an idempotency key, confirm it, capture it, refund it, and list events. Merchants receive webhooks at their own endpoint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data:&lt;/strong&gt; payments (state and version), attempts, ledger entries, idempotency keys with the stored response, outbox events, merchants and payouts. Money is stored as integers in the smallest unit plus a currency code, never as floating point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. High-level design&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Merchant app
     | (1) POST /payments + idempotency key
     v
 API gateway (auth, idempotency check)
     | (2)
     v
 Payment service (state machine) --(3)--&amp;gt; Risk check
     | (4) authorize                           
     v
 Card network
     |
     v (5) one transaction
 Ledger + outbox
     | (6) publish from outbox
     v
 Webhook sender --signed webhook--&amp;gt; Merchant (7)

 Reconciliation job: compares ledger with settlement files from the network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step numbers in the diagram match the list below.&lt;/p&gt;

&lt;p&gt;The numbers match the steps below; the highlighted payment service owns the state machine and the single transaction that makes a payment real.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The merchant's server creates a payment, sending an idempotency key.&lt;/li&gt;
&lt;li&gt;The API gateway authenticates, rate limits and checks the key, then forwards to the payment service.&lt;/li&gt;
&lt;li&gt;The payment service asks the risk check for a score before going further.&lt;/li&gt;
&lt;li&gt;It asks the card network, through an acquirer, to authorize the payment.&lt;/li&gt;
&lt;li&gt;It records the ledger entries and an outbox event in one database transaction.&lt;/li&gt;
&lt;li&gt;The outbox event goes to the webhook sender.&lt;/li&gt;
&lt;li&gt;The webhook sender delivers a signed event to the merchant, retrying until it is acknowledged.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;5. Deep dives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Idempotency:&lt;/strong&gt; the first request with a key inserts it in a unique index and runs; a retry returns the stored response; the same key with different parameters is rejected; concurrent duplicates wait or get a conflict. Keys are kept for about a day.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;State machine:&lt;/strong&gt; only legal transitions are allowed (created, requires action, processing, authorized, succeeded, failed, canceled, refunded). Updates use a version number so two concurrent updates cannot both win, and final states never change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unknown outcomes:&lt;/strong&gt; if the card network times out, the payment is neither failed nor succeeded. Mark it processing, query its status or wait for the asynchronous result, and never blindly retry the authorization. A nightly reconciliation catches whatever slips through.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ledger:&lt;/strong&gt; double-entry and append-only. Every transaction posts entries whose debits equal credits, corrections are new reversing entries, and the sum of all entries must always be zero. Use a relational database with strong isolation, sharded by merchant account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Card data and security:&lt;/strong&gt; card details go from the customer's browser straight to an isolated vault that returns a token, so the rest of the system never sees card numbers and its compliance scope stays small. Keys live in hardware security modules and every access is audited.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fraud and risk:&lt;/strong&gt; a rules and model score computed within a tight time budget before authorization decides to allow, challenge with extra authentication, or block. Decide up front whether the system fails open or closed if the risk service is down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Webhooks:&lt;/strong&gt; delivered at least once from the outbox, signed with a secret and a timestamp so merchants can check authenticity and reject replays, and retried with exponential backoff for days. Merchants must dedupe by event ID and tolerate out-of-order events by fetching the current state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payouts and reconciliation:&lt;/strong&gt; batch jobs pay merchants out, and reconciliation compares the ledger with the settlement files from networks and banks, sending mismatches to a review queue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API evolution:&lt;/strong&gt; pin each merchant to a dated API version so changes never break integrations unexpectedly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Trade-offs:&lt;/strong&gt; strong consistency over availability for money; synchronous confirmation is simpler for merchants but couples them to slow card networks, so asynchronous confirmation with webhooks is more robust; a single home region per payment is simpler and safer than active-active writes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Failures and monitoring.&lt;/strong&gt; On a database failover, idempotency keys and the state machine keep retries safe. A slow card network triggers timeouts and a circuit breaker, with traffic rerouted to another acquirer. Watch authorization success rate by acquirer, p99 latency, the ledger imbalance (which must be zero, and pages someone if not), reconciliation mismatches, webhook delay and the idempotency conflict rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world notes:&lt;/strong&gt; Stripe publicly documents idempotency keys, signed webhooks with automatic retries for several days, and date-based API versions; these are the same patterns described above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; add marketplace payouts, where a platform takes a fee and splits each payment between sellers. Show the ledger entries for one 100 dollar sale with a 10 dollar platform fee, and say what happens if a refund arrives after the seller has been paid out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 7&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A merchant's request times out and the client retries. What prevents a double charge?

&lt;ul&gt;
&lt;li&gt;A) A faster network&lt;/li&gt;
&lt;li&gt;B) An idempotency key that makes the retry return the original result&lt;/li&gt;
&lt;li&gt;C) A bigger database&lt;/li&gt;
&lt;li&gt;D) Sending a new key on every retry&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why store money as integers in minor units?

&lt;ul&gt;
&lt;li&gt;A) Integers use less memory only&lt;/li&gt;
&lt;li&gt;B) Currencies have no decimals&lt;/li&gt;
&lt;li&gt;C) Databases cannot store decimals&lt;/li&gt;
&lt;li&gt;D) Floating point cannot represent many decimal amounts exactly, causing rounding errors&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What is true of a double-entry ledger?

&lt;ul&gt;
&lt;li&gt;A) Every transaction's debits equal its credits, and entries are append-only&lt;/li&gt;
&lt;li&gt;B) Balances are edited in place&lt;/li&gt;
&lt;li&gt;C) It records only credits&lt;/li&gt;
&lt;li&gt;D) It is optional for payment systems&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The card network times out on an authorization. What should the system treat it as?

&lt;ul&gt;
&lt;li&gt;A) A definite failure, so retry at once&lt;/li&gt;
&lt;li&gt;B) A definite success&lt;/li&gt;
&lt;li&gt;C) An unknown outcome to be checked by status query and reconciliation&lt;/li&gt;
&lt;li&gt;D) A reason to delete the payment&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why must a webhook handler be idempotent?

&lt;ul&gt;
&lt;li&gt;A) Webhooks are never repeated&lt;/li&gt;
&lt;li&gt;B) Delivery is at least once with retries, so an event can arrive more than once or out of order&lt;/li&gt;
&lt;li&gt;C) Merchants have only one server&lt;/li&gt;
&lt;li&gt;D) Signatures are optional&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 7 answers
  &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;B&lt;/strong&gt; an idempotency key makes a retry return the stored result instead of charging again.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/api/idempotent_requests" rel="noopener noreferrer"&gt;Stripe: idempotent requests&lt;/a&gt;, on keys, stored responses and pruning after at least 24 hours.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/webhooks" rel="noopener noreferrer"&gt;Stripe: webhooks&lt;/a&gt;, on events, signatures and retries.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/api-versions" rel="noopener noreferrer"&gt;Stripe: how API versioning works&lt;/a&gt;, on versions pinned per account and per request.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://stripe.com/blog/ledger-stripe-system-for-tracking-and-validating-money-movement" rel="noopener noreferrer"&gt;Ledger: Stripe's system for tracking and validating money movement&lt;/a&gt;, Stripe Engineering, 2024.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.pcisecuritystandards.org/standards/" rel="noopener noreferrer"&gt;PCI Security Standards Council&lt;/a&gt;, the owner of PCI DSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ledger, state machine and reconciliation design is a teaching design in the spirit of these sources, not Stripe's internal architecture.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part 7 of 8 in the System Design Learning Path series. Next: part 8.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>payments</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System design case study: YouTube</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 16:31:56 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-case-study-youtube-54f3</link>
      <guid>https://dev.to/mseada/system-design-case-study-youtube-54f3</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 6 of 8 · week 6 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A video platform is two pipelines joined by storage: an upload pipeline that turns each file into many playable versions once, and a watch path that serves those versions from caches near the viewer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Estimate storage and bandwidth for a media product and see why they dominate cost.&lt;/li&gt;
&lt;li&gt;Design resumable upload, a parallel transcoding pipeline and adaptive streaming.&lt;/li&gt;
&lt;li&gt;Explain CDN tiers, counters and how a viral video is kept from overwhelming the origin.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Functional:&lt;/strong&gt; upload videos, process them for any device and bandwidth, watch with fast start and smooth playback, search, likes, comments and view counts. Recommendations are acknowledged but out of scope here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-functional:&lt;/strong&gt; playback starts in about two seconds, very few stalls, uploads that survive bad networks, high availability, and cost control since storage and bandwidth are the big bills.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Estimates.&lt;/strong&gt; The inputs are public statements that YouTube receives more than 500 hours of video a minute and as of 2017 sees more than a billion hours watched a day; storage per hour is an assumption.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quantity&lt;/th&gt;
&lt;th&gt;Calculation&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hours uploaded per day&lt;/td&gt;
&lt;td&gt;500 times 60 times 24&lt;/td&gt;
&lt;td&gt;720,000 hours&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage per day at an assumed 5 GB per hour across all versions&lt;/td&gt;
&lt;td&gt;720,000 times 5 GB&lt;/td&gt;
&lt;td&gt;about 3.6 PB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage per year&lt;/td&gt;
&lt;td&gt;3.6 PB times 365&lt;/td&gt;
&lt;td&gt;about 1.3 EB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Average concurrent viewers&lt;/td&gt;
&lt;td&gt;1 billion hours times 3,600 divided by 86,400&lt;/td&gt;
&lt;td&gt;about 42 million&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Average egress at 2.5 Mbit per second each&lt;/td&gt;
&lt;td&gt;42 million times 2.5 Mbit per second&lt;/td&gt;
&lt;td&gt;about 104 Tbit per second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Watching versus uploading&lt;/td&gt;
&lt;td&gt;1 billion divided by 720,000&lt;/td&gt;
&lt;td&gt;about 1,400 hours watched per hour uploaded&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The lesson: nothing can serve over 100 Tbit per second from one place, so almost all traffic must come from caches near users, and the system is overwhelmingly read-heavy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. API and data model&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Upload:&lt;/strong&gt; create an upload session, send numbered chunks, then mark it complete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch:&lt;/strong&gt; get video metadata, then get a manifest (HLS or DASH) that lists the segments at each quality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Other:&lt;/strong&gt; search by query, like, comment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data:&lt;/strong&gt; video record (owner, title, status, duration, available qualities), comments and counters in the metadata store; original files, segments and manifests in object storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. High-level design&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Creator app
     | (1) resumable upload
     v
 Upload service --(2)--&amp;gt; Raw storage
                            |
                            v (3) transcode job per rendition
                       Transcode farm
                            |
                            v (4) write segments + manifest
          Rendition storage        Metadata DB
                  |
                  v (5) cache fill on first request
              CDN edge  &amp;lt;-----(6) play: manifest, then segments----  Viewer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step numbers in the diagram match the list below.&lt;/p&gt;

&lt;p&gt;The numbers match the steps below; the highlighted transcode farm is where the upload becomes many playable versions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The creator's app uploads the file in chunks and can resume after a failure.&lt;/li&gt;
&lt;li&gt;The upload service writes the original file to raw storage.&lt;/li&gt;
&lt;li&gt;A new-upload event triggers the transcoding farm.&lt;/li&gt;
&lt;li&gt;The farm splits the video into short segments, encodes each at several qualities in parallel, and writes segments and manifests to rendition storage; the metadata store marks the video ready and search is updated.&lt;/li&gt;
&lt;li&gt;The first viewer request pulls segments through the CDN edge cache; later viewers get them from the cache.&lt;/li&gt;
&lt;li&gt;The player downloads the manifest and picks a quality for each segment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;5. Deep dives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resumable upload:&lt;/strong&gt; chunks with checksums, resume from the last acknowledged chunk, and upload straight to storage with signed URLs so upload servers stay light.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transcoding pipeline:&lt;/strong&gt; a graph of tasks (split, encode each quality, package, thumbnails, captions, safety and copyright checks) run by queue-fed workers that autoscale. Tasks are idempotent so a failed one is simply retried. Segment-level parallelism cuts the time to publish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adaptive bitrate streaming:&lt;/strong&gt; each video is cut into segments of a few seconds at several bitrates, and the player measures throughput and buffer to switch quality per segment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDN tiers:&lt;/strong&gt; edge cache, then a regional shield, then origin. Popular videos are cached everywhere; the long tail mostly comes from the regional tier or origin. Signed, expiring URLs control access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metadata and counters:&lt;/strong&gt; a sharded relational store with replicas and a cache for metadata. View counts flow as events into an aggregator, shown approximately and corrected later after fraud filtering.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search:&lt;/strong&gt; an index fed asynchronously from metadata and captions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost control:&lt;/strong&gt; encode into more efficient codecs only for videos that are watched enough to pay back, and move cold content to cheaper storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Trade-offs:&lt;/strong&gt; more qualities improve playback but cost storage and compute; pre-encoding everything is simple but wasteful for videos nobody watches; eventually consistent counters are cheap but lag.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Failures and monitoring.&lt;/strong&gt; A crashed transcoder's task is retried on another worker; a video that keeps failing goes to a dead-letter queue for review. If a video goes viral and misses the cache at many edges, request coalescing and the shield tier turn thousands of misses into one origin fetch. Watch upload success, time to publish, startup time, rebuffer ratio, CDN hit ratio, queue depth and egress cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world notes:&lt;/strong&gt; YouTube built Vitess to scale MySQL by sharding, and Netflix places its own cache servers inside internet providers' networks; both show how far the read path is pushed toward the viewer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; add live streaming to this design. Say what changes in the pipeline (segments are produced continuously), where latency comes from, and what you would do to protect the origin during a major live event.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 6&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why can't origin storage serve all viewers directly?

&lt;ul&gt;
&lt;li&gt;A) Videos are too short&lt;/li&gt;
&lt;li&gt;B) Disks cannot be read&lt;/li&gt;
&lt;li&gt;C) Average viewing needs on the order of 100 Tbit per second, so most traffic must come from caches near users&lt;/li&gt;
&lt;li&gt;D) Players do not support it&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does adaptive bitrate streaming do?

&lt;ul&gt;
&lt;li&gt;A) Cuts video into short segments at several qualities so the player can switch quality per segment&lt;/li&gt;
&lt;li&gt;B) Compresses audio only&lt;/li&gt;
&lt;li&gt;C) Stores the video in the browser&lt;/li&gt;
&lt;li&gt;D) Encrypts the manifest&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why split a video into segments before transcoding?

&lt;ul&gt;
&lt;li&gt;A) To hide it&lt;/li&gt;
&lt;li&gt;B) To shorten file names&lt;/li&gt;
&lt;li&gt;C) To avoid using storage&lt;/li&gt;
&lt;li&gt;D) So segments can be encoded in parallel across workers, cutting the time to publish&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A video goes viral and misses cache at many edges. What protects the origin?

&lt;ul&gt;
&lt;li&gt;A) Delete the video&lt;/li&gt;
&lt;li&gt;B) Request coalescing and a shield tier, so many misses become one origin fetch&lt;/li&gt;
&lt;li&gt;C) Longer segments&lt;/li&gt;
&lt;li&gt;D) Turn caching off&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why do uploads use chunks with resume?

&lt;ul&gt;
&lt;li&gt;A) Large uploads on mobile networks often fail, so only the missing chunks are resent&lt;/li&gt;
&lt;li&gt;B) To encrypt the file&lt;/li&gt;
&lt;li&gt;C) To reduce storage&lt;/li&gt;
&lt;li&gt;D) To skip transcoding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 6 answers
  &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt; about 42 million average viewers at 2.5 Mbit per second is about 104 Tbit per second, far beyond any origin.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.tubefilter.com/2019/05/07/number-hours-video-uploaded-to-youtube-per-minute/" rel="noopener noreferrer"&gt;More than 500 hours of content are now uploaded to YouTube every minute&lt;/a&gt;, Tubefilter, 2019, reporting YouTube's figure.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.cnbc.com/2017/02/27/youtube-viewers-reportedly-watch-1-billion-hours-of-videos-a-day--us-tv-viewers-watch-125-billion-and-dropping.html" rel="noopener noreferrer"&gt;YouTube viewers watch 1 billion hours a day&lt;/a&gt;, CNBC, 2017, reporting YouTube's blog post.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://vitess.io/docs/overview/history/" rel="noopener noreferrer"&gt;Vitess history&lt;/a&gt;, on how YouTube sharded MySQL.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://openconnect.netflix.com/Open-Connect-Overview.pdf" rel="noopener noreferrer"&gt;Open Connect overview&lt;/a&gt; from Netflix, on caches placed inside internet provider networks.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.apple.com/streaming" rel="noopener noreferrer"&gt;HTTP Live Streaming&lt;/a&gt; from Apple, the reference for segmented adaptive streaming.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The upload and transcoding pipeline is a teaching design built on these facts, not YouTube's published architecture.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part 6 of 8 in the System Design Learning Path series. Next: part 7.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System design case study: WhatsApp</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 16:30:32 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-case-study-whatsapp-k5</link>
      <guid>https://dev.to/mseada/system-design-case-study-whatsapp-k5</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 5 of 8 · week 5 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A chat system is a store-and-forward pipeline: hold a persistent connection per user, store each message until the recipient's device confirms it, and push to a connected device the moment it arrives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apply the design method end to end on a real-time messaging product.&lt;/li&gt;
&lt;li&gt;Design delivery guarantees, ordering, group fan-out and presence.&lt;/li&gt;
&lt;li&gt;Explain how end-to-end encryption changes the architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Functional:&lt;/strong&gt; one-to-one and group chat, sent, delivered and read receipts, offline delivery, photos and videos, last seen and typing indicators, multiple devices per user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-functional:&lt;/strong&gt; low latency for online users, no lost messages, order preserved within a chat, high availability, end-to-end encryption, and billions of users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Estimates.&lt;/strong&gt; Meta, then Facebook, reported in 2020 that WhatsApp delivers roughly 100 billion messages a day, which this exercise uses as the input.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quantity&lt;/th&gt;
&lt;th&gt;Calculation&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Average message rate&lt;/td&gt;
&lt;td&gt;100 billion divided by 86,400&lt;/td&gt;
&lt;td&gt;about 1.2 million per second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peak rate at 3 times average&lt;/td&gt;
&lt;td&gt;1.2 million times 3&lt;/td&gt;
&lt;td&gt;about 3.5 million per second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bandwidth at 1 KB per message&lt;/td&gt;
&lt;td&gt;3.5 million times 1 KB&lt;/td&gt;
&lt;td&gt;about 3.5 GB per second, 28 Gbit per second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total if every message were kept&lt;/td&gt;
&lt;td&gt;100 billion times 1 KB&lt;/td&gt;
&lt;td&gt;about 100 TB per day&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backlog if 1% sit undelivered&lt;/td&gt;
&lt;td&gt;1 billion times 1 KB&lt;/td&gt;
&lt;td&gt;about 1 TB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Connection servers&lt;/td&gt;
&lt;td&gt;500 million concurrent connections divided by about 1 million per server&lt;/td&gt;
&lt;td&gt;about 500 servers, plan 2 to 3 times that for headroom and failover&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The key insight is that the server only needs to hold undelivered messages, so storage tracks the backlog, not the total ever sent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. API and data model&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Over the open connection:&lt;/strong&gt; send (message ID, chat ID, recipient, encrypted payload), ack (message ID, status of delivered or read), and ephemeral presence and typing events.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Over HTTPS:&lt;/strong&gt; registration, key upload and media upload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data:&lt;/strong&gt; users, devices, chats and group members, an inbox per recipient device (inbox sequence number, message ID, encrypted payload, expiry), and receipts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. High-level design&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Sender app                                   Receiver app
     |  (1) send, client message ID                ^
     v                                             | (6) deliver, device acks
 Connection server A                       Connection server B
     |  (2)                                        ^
     v                                             | (5) relay if connected
 +----------------+  (4) where is the user?  +-------------+
 |  Chat service  | -----------------------&amp;gt; | Session map |
 +----------------+                          +-------------+
     |  (3) store in recipient inbox
     v                                  (5) if offline: Push gateway -&amp;gt; notification
 +---------------+
 | Message store |
 +---------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step numbers in the diagram match the list below.&lt;/p&gt;

&lt;p&gt;The numbers on the diagram match the steps below, and the chat service is where most design decisions sit.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The sender's app sends the message over its open connection, with a message ID the client generated.&lt;/li&gt;
&lt;li&gt;The connection server forwards it to the chat service.&lt;/li&gt;
&lt;li&gt;The chat service stores it in the recipient's inbox.&lt;/li&gt;
&lt;li&gt;The chat service asks the session map whether the recipient is connected, and to which server.&lt;/li&gt;
&lt;li&gt;If connected, it relays through that connection server; if not, it asks the push gateway to send a notification.&lt;/li&gt;
&lt;li&gt;The recipient's device receives the message and acknowledges it; the ack travels back and the sender sees delivered.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;5. Deep dives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Delivery guarantee:&lt;/strong&gt; at least once with acknowledgements. The client-generated message ID lets the server drop duplicates when a send is retried. The message leaves the inbox only after the device acks, and unread messages expire after a retention period.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ordering:&lt;/strong&gt; the server assigns an inbox sequence number per recipient, and the app shows messages in that order within a chat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Groups:&lt;/strong&gt; fan out on write, storing one copy per member inbox; cap the group size so fan-out stays bounded. Media is uploaded once and referenced.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Presence and typing:&lt;/strong&gt; ephemeral, never stored, sent only to people who have that chat open, and throttled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple devices:&lt;/strong&gt; each device has its own keys and inbox, and the sender encrypts for each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;End-to-end encryption:&lt;/strong&gt; the apps use a protocol like the Signal protocol; the server holds public pre-keys and relays only ciphertext. This means no server-side search or content scanning, and backups need their own encryption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Media:&lt;/strong&gt; the app encrypts the file, uploads it to object storage through a media service, and sends the link and key in the message; downloads use a CDN.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connection tier:&lt;/strong&gt; servers hold the sockets and are nearly stateless. The session map is a sharded in-memory store keyed by user ID, kept fresh by heartbeats and expiry.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Trade-offs:&lt;/strong&gt; store-and-forward is private and cheap but gives no server-side history; fan-out on write makes reads fast but costs writes for big groups; a persistent connection gives low latency but costs battery and connection capacity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Failures and monitoring.&lt;/strong&gt; If a connection server dies, clients reconnect with exponential backoff and jitter to avoid a thundering herd, and session entries expire; messages are safe in the inbox. If the push provider is down, messages stay queued. Watch connected sockets, p99 send-to-deliver latency, ack ratio, inbox depth, push error rate and reconnect rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world note:&lt;/strong&gt; WhatsApp engineers have written publicly about running on Erlang and holding more than a million connections on a single server, which is why the connection tier is so small for its size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; add a status feature (stories that disappear after 24 hours) and message search to this design. Say where the data lives, how long it lives, and what end-to-end encryption forces you to do on the device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 5&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The server keeps a message only until the recipient's device acknowledges it. What does that mean for storage sizing?

&lt;ul&gt;
&lt;li&gt;A) You must store the full history&lt;/li&gt;
&lt;li&gt;B) Storage tracks the undelivered backlog, not the total ever sent&lt;/li&gt;
&lt;li&gt;C) No storage is needed at all&lt;/li&gt;
&lt;li&gt;D) Storage depends only on images&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A client retries a send after a timeout. How does the server avoid delivering it twice?

&lt;ul&gt;
&lt;li&gt;A) Drop every retry&lt;/li&gt;
&lt;li&gt;B) Lock the user&lt;/li&gt;
&lt;li&gt;C) Use a client-generated message ID and deduplicate&lt;/li&gt;
&lt;li&gt;D) Sort by timestamp&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does a delivered tick mean?

&lt;ul&gt;
&lt;li&gt;A) The server got it&lt;/li&gt;
&lt;li&gt;B) The recipient read it&lt;/li&gt;
&lt;li&gt;C) The message was encrypted&lt;/li&gt;
&lt;li&gt;D) The recipient's device received and acknowledged it&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The recipient is offline. What happens?

&lt;ul&gt;
&lt;li&gt;A) The message waits in their inbox and a push notification is sent; it is delivered when the device reconnects&lt;/li&gt;
&lt;li&gt;B) The message is dropped&lt;/li&gt;
&lt;li&gt;C) The sender must resend&lt;/li&gt;
&lt;li&gt;D) The server decrypts and stores the history&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A connection server fails and millions of clients reconnect at once. What reduces the damage?

&lt;ul&gt;
&lt;li&gt;A) Reconnect immediately in a tight loop&lt;/li&gt;
&lt;li&gt;B) Randomized exponential backoff on reconnect&lt;/li&gt;
&lt;li&gt;C) Disable push&lt;/li&gt;
&lt;li&gt;D) Add a bigger cache&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 5 answers
  &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;B&lt;/strong&gt; the server keeps only undelivered messages, so storage follows the backlog.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://techcrunch.com/2020/10/29/whatsapp-is-now-delivering-roughly-100-billion-messages-a-day" rel="noopener noreferrer"&gt;WhatsApp is now delivering roughly 100 billion messages a day&lt;/a&gt;, TechCrunch, October 2020, the source of the volume figure.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://blog.whatsapp.com/on-e-millio-n" rel="noopener noreferrer"&gt;One million&lt;/a&gt; and &lt;a href="https://blog.whatsapp.com/1-million-is-so-2011" rel="noopener noreferrer"&gt;1 million is so 2011&lt;/a&gt; on the WhatsApp blog, on connections per server with FreeBSD and Erlang.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.whatsapp.com/security/WhatsApp-Security-Whitepaper.pdf" rel="noopener noreferrer"&gt;WhatsApp Encryption Overview&lt;/a&gt;, the technical white paper on registration, sessions, groups and media.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://signal.org/docs/" rel="noopener noreferrer"&gt;Signal Protocol specifications&lt;/a&gt;, including X3DH and the Double Ratchet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The delivery, inbox and group fan-out design is a teaching design built on these facts, not WhatsApp's published architecture.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part 5 of 8 in the System Design Learning Path series. Next: part 6.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Designing data-intensive applications: replication, partitioning, quorums</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 06:13:33 +0000</pubDate>
      <link>https://dev.to/mseada/designing-data-intensive-applications-replication-partitioning-quorums-10kk</link>
      <guid>https://dev.to/mseada/designing-data-intensive-applications-replication-partitioning-quorums-10kk</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 4 of 8 · week 4 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When data volume, speed or complexity is the main challenge, the design comes down to four choices: how data is stored, copied, split and kept consistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose a storage engine and data model for a workload.&lt;/li&gt;
&lt;li&gt;Reason about replication, partitioning and the anomalies they create.&lt;/li&gt;
&lt;li&gt;Pick transaction and consistency levels, and decide between batch and stream processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Storage&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Strength&lt;/th&gt;
&lt;th&gt;Used by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;B-tree&lt;/td&gt;
&lt;td&gt;Updates in place, fast reads, mature indexing&lt;/td&gt;
&lt;td&gt;Most relational databases&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LSM-tree&lt;/td&gt;
&lt;td&gt;Fast writes through sequential appends and background compaction&lt;/td&gt;
&lt;td&gt;Cassandra, RocksDB and similar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Row store&lt;/td&gt;
&lt;td&gt;Whole-record reads and writes (OLTP)&lt;/td&gt;
&lt;td&gt;Application databases&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Column store&lt;/td&gt;
&lt;td&gt;Scanning a few columns over many rows (OLAP)&lt;/td&gt;
&lt;td&gt;Warehouses and analytics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Replication&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Leader and followers:&lt;/strong&gt; writes go to the leader and copy to followers, synchronously or asynchronously; simple and common.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-leader:&lt;/strong&gt; several leaders accept writes, useful across regions, but conflicts must be resolved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaderless with quorums:&lt;/strong&gt; with N replicas, a write needs W acknowledgements and a read asks R; when R plus W is greater than N, a read overlaps the latest write.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replication lag&lt;/strong&gt; causes anomalies: reading your own write from a lagging follower, or seeing data go backwards. Route a user's reads to the leader after a write, or track versions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Partitioning&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;By key range:&lt;/strong&gt; keeps related keys together and supports range scans, but sequential keys such as timestamps create hot spots.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;By hash:&lt;/strong&gt; spreads load evenly, but loses range scans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rebalancing:&lt;/strong&gt; use many more partitions than nodes, or consistent hashing, so adding a node moves little data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identifiers:&lt;/strong&gt; avoid a single auto-increment counter at scale; use IDs that combine a timestamp, a shard or machine part and a sequence so they are unique and roughly sortable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Transactions and consistency&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ACID transactions protect against partial failure; &lt;strong&gt;isolation levels&lt;/strong&gt; trade safety for speed: read committed, snapshot isolation and serializable.&lt;/li&gt;
&lt;li&gt;Know the anomalies: dirty reads, lost updates and write skew, where two transactions each read the same data and write different rows so that together they break a rule.&lt;/li&gt;
&lt;li&gt;Distributed transactions with two-phase commit are slow and fragile; prefer sagas where the business allows.&lt;/li&gt;
&lt;li&gt;Consistency ranges from linearizable (acts like one copy) to eventual. Choose the weakest level a feature can tolerate, and the strongest for money and inventory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Batch and stream:&lt;/strong&gt; batch jobs (Spark, MapReduce) process bounded data cheaply and accurately; stream processors (Flink, Kafka Streams) handle unbounded data with low latency and must deal with windows and late events. Design stream jobs to be idempotent so replays give the same result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worked numbers:&lt;/strong&gt; 1 billion users at 1 KB each is about 1 TB. With three replicas that is 3 TB; at 500 GB per node you need about six nodes before growth and headroom. With N=3, W=2 and R=2 a read always overlaps the latest acknowledged write.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world examples&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Amazon Dynamo (2007):&lt;/strong&gt; a published design for a highly available key-value store using leaderless replication and quorums; it inspired many later databases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Spanner (2012):&lt;/strong&gt; a globally distributed database that offers strong consistency by using tightly synchronized clocks, showing that the trade-off can be pushed with specialized hardware.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instagram IDs:&lt;/strong&gt; the team documented generating sortable IDs from a timestamp, a shard ID and a sequence, so each shard creates unique IDs with no central counter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; design the storage for a chat history store holding 100 billion messages. Choose the engine, the partition key, the replication setting and the consistency level, and explain how you would serve the latest 50 messages of a conversation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 4&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why are LSM-trees good for write-heavy workloads?

&lt;ul&gt;
&lt;li&gt;A) They give faster random reads than B-trees in every case&lt;/li&gt;
&lt;li&gt;B) Writes are sequential appends merged later by compaction&lt;/li&gt;
&lt;li&gt;C) They need no disk&lt;/li&gt;
&lt;li&gt;D) They give transactions across nodes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;With N=3 replicas, which setting makes a read overlap the latest acknowledged write?

&lt;ul&gt;
&lt;li&gt;A) W=1, R=1&lt;/li&gt;
&lt;li&gt;B) W=1, R=2&lt;/li&gt;
&lt;li&gt;C) W=2, R=2&lt;/li&gt;
&lt;li&gt;D) W=0, R=3&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What causes the read-your-writes anomaly?

&lt;ul&gt;
&lt;li&gt;A) Too many indexes&lt;/li&gt;
&lt;li&gt;B) Clock skew in browsers&lt;/li&gt;
&lt;li&gt;C) Encrypted disks&lt;/li&gt;
&lt;li&gt;D) Reading from a follower that has not yet received your recent write&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why hash-partition a table keyed by timestamp instead of using key ranges?

&lt;ul&gt;
&lt;li&gt;A) All current writes hit one range partition, a hot spot, while hashing spreads them&lt;/li&gt;
&lt;li&gt;B) Timestamps are sensitive data&lt;/li&gt;
&lt;li&gt;C) Range queries become faster&lt;/li&gt;
&lt;li&gt;D) It removes the need for replicas&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Two on-call doctors each see the other on call and both go off call. What is this and what prevents it?

&lt;ul&gt;
&lt;li&gt;A) A dirty read, fixed by a cache&lt;/li&gt;
&lt;li&gt;B) Write skew, fixed by serializable isolation or explicit locking&lt;/li&gt;
&lt;li&gt;C) A network partition, fixed by retries&lt;/li&gt;
&lt;li&gt;D) A deadlock, fixed by more replicas&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 4 answers
  &lt;ol&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt; with N=3, W=2 and R=2, R plus W is 4, which is greater than N, so a read overlaps the latest write.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dataintensive.net/" rel="noopener noreferrer"&gt;Designing Data-Intensive Applications&lt;/a&gt; by Martin Kleppmann, the main reference for this module.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://courses.cs.washington.edu/courses/cse444/21wi/papers/p205-decandia.pdf" rel="noopener noreferrer"&gt;Dynamo: Amazon's highly available key-value store&lt;/a&gt;, the 2007 paper (hosted copy).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://research.google/pubs/pub39966/" rel="noopener noreferrer"&gt;Spanner: Google's globally distributed database&lt;/a&gt;, the OSDI 2012 paper.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c" rel="noopener noreferrer"&gt;Sharding and IDs at Instagram&lt;/a&gt;, on time-sortable 64-bit IDs per shard.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Part 4 of 8 in the System Design Learning Path series. Next: part 5.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>database</category>
      <category>architecture</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Event-driven architecture: events, outbox and idempotency</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 06:12:58 +0000</pubDate>
      <link>https://dev.to/mseada/event-driven-architecture-events-outbox-and-idempotency-n00</link>
      <guid>https://dev.to/mseada/event-driven-architecture-events-outbox-and-idempotency-n00</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 3 of 8 · week 3 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In an event-driven system a service records a fact that has happened and others react to it on their own time, which absorbs spikes and lets you add consumers without touching the producer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tell events, commands and queries apart and name them correctly.&lt;/li&gt;
&lt;li&gt;Choose between a queue and a log, and design for duplicates and ordering.&lt;/li&gt;
&lt;li&gt;Apply the outbox, idempotent consumer, dead-letter and CQRS patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Concepts&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Event&lt;/td&gt;
&lt;td&gt;A fact that already happened, named in the past tense&lt;/td&gt;
&lt;td&gt;OrderPlaced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command&lt;/td&gt;
&lt;td&gt;A request to a specific service to do something&lt;/td&gt;
&lt;td&gt;ChargeCard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query&lt;/td&gt;
&lt;td&gt;A request for data&lt;/td&gt;
&lt;td&gt;GetOrder&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queue&lt;/td&gt;
&lt;td&gt;Each message goes to one consumer and is removed&lt;/td&gt;
&lt;td&gt;Work distribution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Log&lt;/td&gt;
&lt;td&gt;Ordered, retained stream that many consumers read at their own pace&lt;/td&gt;
&lt;td&gt;Event streaming, replay&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Consumer group&lt;/td&gt;
&lt;td&gt;Instances that share the partitions of a topic&lt;/td&gt;
&lt;td&gt;Scale out a consumer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Delivery and ordering&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Most systems deliver at least once, so a message can arrive twice. Make handlers &lt;strong&gt;idempotent&lt;/strong&gt;, for example by recording processed event IDs, so duplicates do no harm.&lt;/li&gt;
&lt;li&gt;Ordering is only guaranteed within a partition. Use a key such as the order ID so all events for one order land in the same partition.&lt;/li&gt;
&lt;li&gt;Move messages that keep failing to a &lt;strong&gt;dead-letter queue&lt;/strong&gt; after limited retries, and alert on it.&lt;/li&gt;
&lt;li&gt;Version event schemas, keep changes backward compatible and register them so consumers can evolve safely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Patterns&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Outbox:&lt;/strong&gt; write the data change and the event in one database transaction, then a relay publishes the event, so you never update data without publishing or the reverse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saga:&lt;/strong&gt; coordinate multi-step workflows through events, with compensating events on failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CQRS:&lt;/strong&gt; keep the write model separate from one or more read-optimized models that are updated from events.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event sourcing:&lt;/strong&gt; store the sequence of events as the source of truth and rebuild state from it; powerful for audit, but adds complexity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Worked example, order flow.&lt;/strong&gt; The Order service saves the order and writes OrderPlaced to its outbox. Inventory reacts and emits StockReserved. Payment reacts and emits PaymentCaptured. Shipping starts only after that. Later the team adds an email service and an analytics pipeline as new consumers of the same events, with no change to Order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pitfalls:&lt;/strong&gt; treating events as remote calls that expect a reply, event chains nobody can follow without tracing, breaking schema changes, assuming global ordering, and putting huge payloads in events instead of references.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world examples&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LinkedIn and Kafka:&lt;/strong&gt; LinkedIn built Kafka around 2010 to move activity and operational data between systems at scale, and open sourced it; it became the standard log for event streaming.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stripe webhooks:&lt;/strong&gt; Stripe tells merchants about payments by sending events to their endpoint, retrying on failure, so merchants must handle duplicates and out-of-order delivery. It is a public example of at-least-once delivery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Netflix:&lt;/strong&gt; it streams very large volumes of operational and viewing events through a central pipeline for monitoring and analytics, decoupling the producers from the many teams consuming them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; design the events for a food delivery order (placed, accepted, picked up, delivered, refunded). Choose partition keys, say where you need an outbox, and describe what a consumer does on a duplicate and on an out-of-order event.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 3&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Which of these is a command rather than an event?

&lt;ul&gt;
&lt;li&gt;A) OrderPlaced&lt;/li&gt;
&lt;li&gt;B) PaymentCaptured&lt;/li&gt;
&lt;li&gt;C) ChargeCard&lt;/li&gt;
&lt;li&gt;D) UserRegistered&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does at-least-once delivery mean for a consumer?

&lt;ul&gt;
&lt;li&gt;A) A message may arrive more than once, so handlers must be idempotent&lt;/li&gt;
&lt;li&gt;B) Duplicates never happen&lt;/li&gt;
&lt;li&gt;C) Messages may be lost&lt;/li&gt;
&lt;li&gt;D) Exactly one copy is always delivered&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does the outbox pattern guarantee?

&lt;ul&gt;
&lt;li&gt;A) Messages are encrypted&lt;/li&gt;
&lt;li&gt;B) Ordering across all topics&lt;/li&gt;
&lt;li&gt;C) Faster consumers&lt;/li&gt;
&lt;li&gt;D) The data change and the event are committed together and the event is then published reliably&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How do you keep all events for one order in order on a partitioned log?

&lt;ul&gt;
&lt;li&gt;A) Use a random key&lt;/li&gt;
&lt;li&gt;B) Use the order ID as the key so they share a partition&lt;/li&gt;
&lt;li&gt;C) Create a topic per event&lt;/li&gt;
&lt;li&gt;D) Make messages bigger&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What is CQRS?

&lt;ul&gt;
&lt;li&gt;A) A type of queue&lt;/li&gt;
&lt;li&gt;B) A database index&lt;/li&gt;
&lt;li&gt;C) Separating the write model from one or more read-optimized models, often updated by events&lt;/li&gt;
&lt;li&gt;D) A caching protocol&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 3 answers
  &lt;ol&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt; the outbox writes the data change and the event in one transaction, so neither can be lost without the other.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://kafka.apache.org/documentation/" rel="noopener noreferrer"&gt;Apache Kafka documentation&lt;/a&gt;, starting with the introduction to event streaming.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying" rel="noopener noreferrer"&gt;The Log: what every software engineer should know about real-time data's unifying abstraction&lt;/a&gt; by Jay Kreps of LinkedIn, on why a log underlies messaging and replication.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://microservices.io/patterns/data/transactional-outbox" rel="noopener noreferrer"&gt;Transactional outbox pattern&lt;/a&gt; on microservices.io.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/webhooks" rel="noopener noreferrer"&gt;Stripe webhooks documentation&lt;/a&gt;, a public example of at-least-once event delivery with retries and signatures.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter" rel="noopener noreferrer"&gt;Amazon Builders' Library: timeouts, retries, and backoff with jitter&lt;/a&gt;, for safe retries and idempotent APIs.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Part 3 of 8 in the System Design Learning Path series. Next: part 4.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>eventdriven</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Microservices: boundaries, sagas and failure</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 06:11:51 +0000</pubDate>
      <link>https://dev.to/mseada/microservices-boundaries-sagas-and-failure-769</link>
      <guid>https://dev.to/mseada/microservices-boundaries-sagas-and-failure-769</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 2 of 8 · week 2 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Microservices let many teams release and scale parts of a system independently, but they trade simple code for a distributed system, so use them when the organization needs the independence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decide between a modular monolith and microservices for a given team and product.&lt;/li&gt;
&lt;li&gt;Draw service boundaries, own data per service and choose how services communicate.&lt;/li&gt;
&lt;li&gt;Keep multi-service workflows consistent and resilient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Principles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boundaries follow business capabilities, so a change usually touches one service.&lt;/li&gt;
&lt;li&gt;Each service owns its data; others reach it only through its API or events.&lt;/li&gt;
&lt;li&gt;Services deploy independently, and the team that builds a service runs it.&lt;/li&gt;
&lt;li&gt;Start with a well-structured modular monolith and split out services when a real need appears.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Communication&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Style&lt;/th&gt;
&lt;th&gt;Use it for&lt;/th&gt;
&lt;th&gt;Watch out for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Synchronous (REST, gRPC)&lt;/td&gt;
&lt;td&gt;Queries and steps where the caller needs an answer now&lt;/td&gt;
&lt;td&gt;Latency adds up, failures cascade&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Asynchronous (events, queues)&lt;/td&gt;
&lt;td&gt;Notifying others, long steps, absorbing spikes&lt;/td&gt;
&lt;td&gt;Harder to follow, needs idempotency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API gateway&lt;/td&gt;
&lt;td&gt;One entry point for clients: auth, limits, routing&lt;/td&gt;
&lt;td&gt;Keep business logic out of it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service discovery&lt;/td&gt;
&lt;td&gt;Finding healthy instances&lt;/td&gt;
&lt;td&gt;Needs health checks and fast failover&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Keeping workflows consistent:&lt;/strong&gt; a single database transaction cannot span services, so use a &lt;strong&gt;saga&lt;/strong&gt;: a sequence of local steps where each step has a compensating action if a later step fails. A saga can be orchestrated by one coordinator or choreographed through events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worked example, checkout.&lt;/strong&gt; Cart, Order, Inventory, Payment and Shipping are separate services. The order saga reserves stock, charges the card, then books shipping. If the charge fails, the compensating action releases the reserved stock and marks the order failed. Each step is idempotent so a retry does no harm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resilience patterns:&lt;/strong&gt; timeouts on every call; retries with exponential backoff and jitter; circuit breakers that stop calling a failing service for a while; bulkheads that isolate resources per dependency. Be careful with retries: if three layers each try a call three times in total, one user action can become 27 calls to the bottom service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delivery:&lt;/strong&gt; one repository or several, but each service has its own pipeline, containers, canary releases and rollback. Use contract tests so teams can change services without breaking each other, and pass a trace ID through every call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world examples&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Amazon and Netflix:&lt;/strong&gt; both moved from large applications to many small services owned by single teams, which let them release thousands of times a day, at the cost of heavy investment in tooling and operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Segment (2018):&lt;/strong&gt; the company published that it moved a set of tightly coupled microservices back into one service because the operational cost outweighed the benefits at its team size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shopify:&lt;/strong&gt; it runs a very large modular monolith with enforced internal boundaries, showing that good structure matters more than the number of deployables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; take the checkout example and write the saga as a table of steps, compensating actions and events. Then list two reasons you would keep it as a modular monolith for a team of eight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 2&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When are microservices a good choice?

&lt;ul&gt;
&lt;li&gt;A) A team of three building a simple app&lt;/li&gt;
&lt;li&gt;B) You want fewer deployments&lt;/li&gt;
&lt;li&gt;C) Many teams need independent releases and parts of the system scale differently&lt;/li&gt;
&lt;li&gt;D) You want to share one database across services&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What is a compensating action in a saga?

&lt;ul&gt;
&lt;li&gt;A) Releasing reserved stock when the payment step fails&lt;/li&gt;
&lt;li&gt;B) Adding a cache&lt;/li&gt;
&lt;li&gt;C) Rolling back one database transaction across services&lt;/li&gt;
&lt;li&gt;D) Locking all tables&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does a circuit breaker do?

&lt;ul&gt;
&lt;li&gt;A) Encrypts calls&lt;/li&gt;
&lt;li&gt;B) Caches responses&lt;/li&gt;
&lt;li&gt;C) Balances load&lt;/li&gt;
&lt;li&gt;D) Stops calling a failing dependency for a while so failure does not cascade&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What do the Segment and Shopify examples show?

&lt;ul&gt;
&lt;li&gt;A) Monoliths are obsolete&lt;/li&gt;
&lt;li&gt;B) Microservices bring operational cost, and a well-structured modular monolith can be the better choice&lt;/li&gt;
&lt;li&gt;C) You should always use microservices&lt;/li&gt;
&lt;li&gt;D) You should never split a system&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Three layers each try a call three times in total. How many calls can reach the bottom service from one user action?

&lt;ul&gt;
&lt;li&gt;A) 3&lt;/li&gt;
&lt;li&gt;B) 9&lt;/li&gt;
&lt;li&gt;C) 27&lt;/li&gt;
&lt;li&gt;D) 1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 2 answers
  &lt;ol&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt; three layers each making three attempts give 3 times 3 times 3, which is 27 calls.&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://martinfowler.com/articles/microservices.html" rel="noopener noreferrer"&gt;Microservices&lt;/a&gt; by James Lewis and Martin Fowler, the article that defined the style and its characteristics.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://microservices.io/patterns/data/saga.html" rel="noopener noreferrer"&gt;Saga pattern&lt;/a&gt; on microservices.io, for orchestration versus choreography.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter" rel="noopener noreferrer"&gt;Timeouts, retries, and backoff with jitter&lt;/a&gt; from the Amazon Builders' Library, the source for the retry pitfalls above.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.infoq.com/news/2018/07/segment-microservices" rel="noopener noreferrer"&gt;Why Segment returned to a monolith&lt;/a&gt; on InfoQ, summarizing Segment's own write-up.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://shopify.engineering/deconstructing-monolith-designing-software-maximizes-developer-productivity" rel="noopener noreferrer"&gt;Deconstructing the monolith&lt;/a&gt; from Shopify Engineering, on the modular monolith.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.primevideotech.com/video-streaming/scaling-up-the-prime-video-audio-video-monitoring-service-and-reducing-costs-by-90" rel="noopener noreferrer"&gt;Prime Video: scaling up the monitoring service and reducing costs by 90%&lt;/a&gt;, with an &lt;a href="https://infoq.com/news/2023/05/prime-ec2-ecs-saves-costs" rel="noopener noreferrer"&gt;InfoQ summary&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Amazon and Netflix history in this module is from general knowledge and has no cited source here; add one if you want it referenced.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part 2 of 8 in the System Design Learning Path series. Next: part 3.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>microservices</category>
      <category>architecture</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System design fundamentals: estimate, scale and trade off</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 05:29:19 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-fundamentals-estimate-scale-and-trade-off-1ggm</link>
      <guid>https://dev.to/mseada/system-design-fundamentals-estimate-scale-and-trade-off-1ggm</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 1 of 8 · week 1 of the learning path&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Every large design is the same few building blocks combined to meet numbers, so learn the blocks and learn to estimate before drawing any boxes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Turn a product request into functional and non-functional requirements.&lt;/li&gt;
&lt;li&gt;Do back-of-envelope estimates for traffic, storage and bandwidth.&lt;/li&gt;
&lt;li&gt;Explain what each core building block does and when to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Requirements first&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Functional:&lt;/strong&gt; what the system does (send a message, upload a video, charge a card).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-functional:&lt;/strong&gt; how well it does it: scale, latency, availability, durability, consistency, security and cost.&lt;/li&gt;
&lt;li&gt;Ask about scope and priorities before designing; a design for 1,000 users and one for 100 million are different systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Estimation cheat sheet&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Fact&lt;/th&gt;
&lt;th&gt;Rule of thumb&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Seconds in a day&lt;/td&gt;
&lt;td&gt;About 86,400, so requests per day divided by 86,400 gives average QPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peak versus average&lt;/td&gt;
&lt;td&gt;Plan for 2 to 3 times average, more for spiky products&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory read&lt;/td&gt;
&lt;td&gt;About 100 nanoseconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SSD random read&lt;/td&gt;
&lt;td&gt;About 100 microseconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Round trip inside one datacenter&lt;/td&gt;
&lt;td&gt;About 0.5 milliseconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Round trip across continents&lt;/td&gt;
&lt;td&gt;About 150 milliseconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage&lt;/td&gt;
&lt;td&gt;Records per day times record size times retention&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Worked example:&lt;/strong&gt; 10 million daily users each make 20 reads and 2 writes a day. Reads are 200 million a day, about 2,300 per second on average and about 7,000 at a 3x peak. Writes are 20 million a day, about 230 per second and about 700 at peak. At 1 KB per write, that is 20 GB a day, or about 7.3 TB a year before replication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building blocks&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Block&lt;/th&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;Key choices&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Load balancer&lt;/td&gt;
&lt;td&gt;Spreads requests across instances&lt;/td&gt;
&lt;td&gt;Layer 4 or layer 7, health checks, algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache&lt;/td&gt;
&lt;td&gt;Serves hot data from memory&lt;/td&gt;
&lt;td&gt;Cache-aside versus write-through, eviction, expiry, stampede protection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CDN&lt;/td&gt;
&lt;td&gt;Serves static and cacheable content near users&lt;/td&gt;
&lt;td&gt;What to cache, expiry, invalidation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Relational database&lt;/td&gt;
&lt;td&gt;Structured data with transactions&lt;/td&gt;
&lt;td&gt;Indexes, replicas, sharding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NoSQL store&lt;/td&gt;
&lt;td&gt;Scale and flexible models&lt;/td&gt;
&lt;td&gt;Key-value, document, wide-column, graph&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queue or log&lt;/td&gt;
&lt;td&gt;Decouples producers and consumers, absorbs spikes&lt;/td&gt;
&lt;td&gt;Ordering, retention, delivery guarantees&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Object storage&lt;/td&gt;
&lt;td&gt;Cheap durable storage for large files&lt;/td&gt;
&lt;td&gt;Lifecycle, access control&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Search index&lt;/td&gt;
&lt;td&gt;Full text and filtered queries&lt;/td&gt;
&lt;td&gt;Refresh lag, relevance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rate limiter&lt;/td&gt;
&lt;td&gt;Protects services from abuse and overload&lt;/td&gt;
&lt;td&gt;Token bucket, per-user or per-key limits&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Scaling basics:&lt;/strong&gt; make services stateless so any instance can serve any request; scale out behind a load balancer; cache reads; replicate data for reads and safety; shard data when one node cannot hold or write it all. When the network splits, a distributed store must choose consistency or availability, so decide per feature which matters more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design exercise:&lt;/strong&gt; a URL shortener gets 100 million new links a month with ten reads per write. Estimate write and read QPS, storage over five years and cache size for the hottest 20% of links, then list the blocks you would use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiz 1&lt;/strong&gt; (5 questions, pass mark 4)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;About what is the average QPS for 86.4 million requests a day?

&lt;ul&gt;
&lt;li&gt;A) 100&lt;/li&gt;
&lt;li&gt;B) 1,000&lt;/li&gt;
&lt;li&gt;C) 10,000&lt;/li&gt;
&lt;li&gt;D) 86,400&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why is a stateless service easy to scale?

&lt;ul&gt;
&lt;li&gt;A) It uses sticky sessions&lt;/li&gt;
&lt;li&gt;B) It keeps sessions in local memory&lt;/li&gt;
&lt;li&gt;C) Any instance can serve any request, so you add instances behind a load balancer&lt;/li&gt;
&lt;li&gt;D) It needs a single large server&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What is cache-aside?

&lt;ul&gt;
&lt;li&gt;A) The cache is the only store&lt;/li&gt;
&lt;li&gt;B) Reads bypass the cache&lt;/li&gt;
&lt;li&gt;C) The database pushes every write into the cache&lt;/li&gt;
&lt;li&gt;D) The app checks the cache first and, on a miss, reads the database and fills the cache&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What does a CDN mainly do?

&lt;ul&gt;
&lt;li&gt;A) Serves static and cacheable content from locations near users, cutting latency and origin load&lt;/li&gt;
&lt;li&gt;B) Stores financial transactions&lt;/li&gt;
&lt;li&gt;C) Runs SQL queries&lt;/li&gt;
&lt;li&gt;D) Encrypts the database&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How should you size for traffic peaks?

&lt;ul&gt;
&lt;li&gt;A) Use the average only&lt;/li&gt;
&lt;li&gt;B) Ignore peaks&lt;/li&gt;
&lt;li&gt;C) Plan for a multiple of average, commonly 2 to 3 times or more, plus headroom&lt;/li&gt;
&lt;li&gt;D) Assume every second is a peak&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;
  Quiz 1 answers
  &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;B&lt;/strong&gt; 86.4 million divided by 86,400 seconds is 1,000 requests per second.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources and further reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dzone.com/articles/every-programmer-should-know" rel="noopener noreferrer"&gt;Latency numbers every programmer should know&lt;/a&gt;, the Jeff Dean and Peter Norvig figures behind the estimation table; the numbers are rough and dated, so use them for orders of magnitude.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/donnemartin/system-design-primer" rel="noopener noreferrer"&gt;System Design Primer&lt;/a&gt;, an open study guide covering the building blocks in this module.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dataintensive.net/" rel="noopener noreferrer"&gt;Designing Data-Intensive Applications&lt;/a&gt; by Martin Kleppmann, for caching, replication and consistency in depth.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Part 1 of 8 in the System Design Learning Path series. Next: part 2.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System design learning path: from fundamentals to WhatsApp, YouTube and Stripe</title>
      <dc:creator>mseada</dc:creator>
      <pubDate>Thu, 22 Oct 2026 05:05:32 +0000</pubDate>
      <link>https://dev.to/mseada/system-design-learning-path-from-fundamentals-to-whatsapp-youtube-and-stripe-4o69</link>
      <guid>https://dev.to/mseada/system-design-learning-path-from-fundamentals-to-whatsapp-youtube-and-stripe-4o69</guid>
      <description>&lt;p&gt;An eight-week path that teaches software engineers to design large systems: core building blocks, three architecture styles, then full designs of WhatsApp, YouTube and Stripe, with a quiz after every module.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; every engineer can take a vague product idea, ask the right questions, estimate the load, sketch an architecture and defend its trade-offs, using one repeatable method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audience:&lt;/strong&gt; backend, full-stack and mobile engineers, tech leads and architects. Basic knowledge of web APIs and databases is assumed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Format:&lt;/strong&gt; 8 modules, about 3 hours per week. Each module has a short talk, self-study reading, one design exercise and a 5-question quiz (pass mark 4 of 5). The three case studies each include an architecture diagram and worked numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The design method used in every module&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clarify requirements, both functional and non-functional (scale, latency, availability, consistency).&lt;/li&gt;
&lt;li&gt;Estimate load and storage with back-of-envelope math.&lt;/li&gt;
&lt;li&gt;Define the API and the core data model.&lt;/li&gt;
&lt;li&gt;Draw the high-level architecture.&lt;/li&gt;
&lt;li&gt;Deep dive on the hardest two or three parts.&lt;/li&gt;
&lt;li&gt;Name the trade-offs, failure modes and what you would monitor.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Levels&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;Requirements&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Foundation&lt;/td&gt;
&lt;td&gt;Quizzes 1 to 4 passed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Practitioner&lt;/td&gt;
&lt;td&gt;Foundation, Quizzes 5 to 7 passed, and the final assessment at 9 of 12 or more&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Architect&lt;/td&gt;
&lt;td&gt;Practitioner, final assessment at 11 of 12 or more, and the capstone at 70 points or more&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Outcomes by the end&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Size a system from users and usage, and spot the bottleneck before building.&lt;/li&gt;
&lt;li&gt;Choose between monolith, microservices and event-driven styles, and say why.&lt;/li&gt;
&lt;li&gt;Reason about replication, partitioning, transactions and consistency.&lt;/li&gt;
&lt;li&gt;Design a chat system, a video platform and a payment system, including failure handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The series&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;System design fundamentals: estimate, scale and trade off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Microservices: boundaries, sagas and failure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Event-driven architecture: events, outbox and idempotency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Designing data-intensive applications: replication, partitioning, quorums&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;System design case study: WhatsApp&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;System design case study: YouTube&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;System design case study: Stripe and payment systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Capstone and final assessment&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each post ends with a quiz. Answers are hidden in a collapsible block, so try the questions first.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
