Cart and checkout
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 12 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many cart writes and orders a second when a sale opens?

      How much CPU does pricing need at the sale peak?

        How many shards does the stock-and-holds database need?

          How much storage do carts and live quotes need?

            How many units sit held at the peak, depending on when you hold?

              Build-up · 5 steps

              Build the high-level design

              One functional requirement at a time, ending with a design that works for one region at moderate traffic.

              Step 1 of 5

              Add, change and remove items

              Carts sit in a key-value store partitioned by cart ID, each line its own item, so two devices adding different items never collide. Titles, prices and stock are read fresh from the online store’s read models.

              6 interview moments

              You’re the candidate

              The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

              1. Deep dive 1 of 6

                Interviewer

                “Millions add, remove and forget items, and a shopper whose “Add to cart” fails often doesn’t tap again. Where do you keep the cart?”

                Your move. Pick an approach:

              2. Deep dive 2 of 6

                Interviewer

                “A seller reprices, a coupon expires at midnight, a bank offer needs one bank’s card. How do you charge exactly what you showed?”

                Your move. Pick an approach:

              3. Deep dive 3 of 6

                Interviewer

                “Two shoppers tap “Place order” for the last Phone Z5 at the Mumbai FC in the same millisecond. How do you sell it once?”

                Your move. Pick an approach:

              4. Deep dive 4 of 6

                Interviewer

                “Double taps, 4G timeouts, refreshes, two tabs and your own retries between services. How do you create exactly one order and one charge?”

                Your move. Pick an approach:

              5. Deep dive 5 of 6

                Interviewer

                “About 23M carts a day are abandoned. How do you send a reminder an hour after the last edit?”

                Your move. Pick an approach:

              6. Deep dive 6 of 6

                Interviewer

                “At midnight a festive sale opens and traffic jumps 10× within a minute. How do you keep “Place order” working?”

                Your move. Pick an approach:

              Build-up · 8 steps

              Follow one shopper from tap to order

              The cart half is wide, partitioned and always writable. The checkout half is narrow, transactional and driven by deadlines. Kafka carries what happened to everyone who reacts later.

              Step 1 of 8

              Add to cart

              One conditional write to that line’s item in a three-zone store, deduplicated by the tap ID, so a retried tap is not a second phone.