Low-Level Design (Object-Oriented Design) Module 15
Case studies: platforms and apps interview questions
Interview questions on “Case studies: platforms and apps”: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
Why does a chat application order messages by a sequence number per conversation rather than by timestamps?
Because clocks disagree and a counter cannot. A phone's clock can be minutes off, so sorting by the sender's time can put a reply before the question it answers, and two servers whose clocks differ by a few milliseconds can do the same with a quick reply. Arrival order differs on every phone, because pushes take different paths. A sequence number is given by one owner, the conversation, when it stores the message, so every phone sorts the same way and can also see a gap: a phone holding 40 and 42 knows that 41 is missing and asks for it. The time is still stored for display next to the message, but never used to order it. One counter per conversation is enough, because no phone needs an order across conversations.
From the lesson Low-level design: chat application
-
Fresher to mid
Why model a kanban board's columns as the states of a workflow, rather than as a status string on each task?
Answered in the lesson Low-level design: task manager and kanban board
-
Fresher to mid
Why does a version store hash an object's type and size together with its content?
So that an ID names exactly one object of one kind. If only the content were hashed, a file whose bytes happened to equal a tree's encoding would get the tree's ID, and the store could hand back a tree where a file was expected. Hashing a header with the type keeps a blob and a tree with equal bytes apart. The size makes the encoding self-delimiting: a reader knows where the header ends and how many bytes of content follow, so the bytes can be checked against the ID when they are read back. Git hashes the same header before the content: the type, a space, the length and a zero byte. One consequence surprises people: a blob's ID is not the plain SHA-256 of the file, so a checksum tool shows another number.
From the lesson Low-level design: mini version control
-
Fresher to mid
Why does a cricket scorecard design store valid balls rather than overs written as 19.4?
Answered in the lesson Low-level design: live cricket scorecard
-
Fresher to mid
What problem does the Bridge pattern solve in a notification service with several kinds of message and several channels?
It stops the classes from multiplying. Kinds of message (sign-in codes, order updates, promotions) and channels (SMS, email, push) change for different reasons: a new campaign adds a kind, a new provider adds a channel. With a class for every pair, three kinds and three channels need nine classes, and every new channel adds one per kind. The Bridge splits the two: a notification type decides what to say, how urgent it is and how long it is worth delivering; a channel delivers a short or a long text. The service asks the type for content in the channel's form and hands it to the channel. Three and three then need six classes, and a new channel is one class that every kind can use at once.
From the lesson Low-level design: notification service
-
Fresher to mid
Why does an online exam take each section's deadline from the server's clock, fixed when the section opens?
Because every candidate must get the same time, and only the server's clock is the same for all of them. A browser's clock can be minutes wrong, and a browser can be changed by the person using it, so a deadline checked there can be moved. Fixing the deadline once, when the section opens, means that nothing the browser does later can move it: a disconnect costs the candidate only the minutes they were away, and a reconnect does not restart the section. The browser still shows a countdown, but each answer from the server corrects it with the seconds left. Code that needs the time asks an injected clock, so tests can move time by hand instead of waiting.
From the lesson Low-level design: online exam with negative marking
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
Users report that a message sometimes appears twice for everyone in a group, usually when the sender's phone switches from Wi-Fi to mobile data while sending. Explain how this happens, then design the fix on the phone and on the server.
- What it tests
- Seeing a retry after a lost reply as the cause, idempotent sends keyed by sender and client id, the order of the server's checks, and how long the keys are kept.
- First step
- Draw the send as three steps: the request reaches the server, the server stores and pushes the message, and the reply travels back. If the network changes during the third step, the phone never hears back and sends again. Then ask what the second request could carry that tells the server it has seen this message before.
- Follow-ups
-
- The phone was offline for three days before it retried. Does the fix still hold?
- An admin switched on announcement mode between the two attempts. What should the retry get?
- Two phones of the same person send at the same moment. Can their client ids collide?
From the lesson Low-level design: chat application
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to staff
A group of 200 shows "read by N" under every message, and its receipts table grows by about two million rows a day. Redesign receipts so that storage stays small and the counts stay correct. What do you give up?
- What it tests
- Cumulative marks instead of a row per message, marks that only move forward, counting readers without a loop over members, late joiners, and what is lost with per-message rows.
- First step
- Check the estimate first: 5,000 messages a day, 199 recipients each, once for delivered and once for read, is about two million rows. Then notice that people read a conversation in order, so one number per member, "read up to seq N", can stand for every read row of that member.
- Follow-ups
-
- How do you count "read by" for a message without a loop over 200 members?
- A member joins after message 100. Does message 50 count them?
- Product wants to show when each person read each message. What changes?
From the lesson Low-level design: chat application
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Senior to staff
A chat server holding 50,000 connections restarts. For a minute the new server is overloaded, and afterwards some users report missing messages from around the restart. Explain both problems and design what the phones and the server should do.
- What it tests
- Reconnect storms and jittered backoff, why a successful socket write is not a receipt, filling gaps by sequence number, and sizing the recovery with numbers.
- First step
- Separate the two problems. The overload is 50,000 phones reconnecting in the same instant; the missing messages are pushes written to sockets that died, which nothing told the phones about. Then put a number on the first: how many new connections a second can one server accept, and how long 50,000 take at that rate?
- Follow-ups
-
- What should the first reconnect delay be, and why random?
- How does a phone learn which messages it missed?
- The server accepts 2,000 new connections a second. How long until everyone is back?
From the lesson Low-level design: chat application
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Asha moves a card to Review. A minute later Ben moves it back to In progress because the review found a bug. Then Asha presses undo. What should happen, and how does your design decide it?
- What it tests
- Undo as a command with a precondition, versions on tasks, keeping the history append-only, and what to tell the person whose undo is refused.
- First step
- Ask what reversing Asha's move would do now. The card is in In progress because Ben put it there, so moving it back to where Asha found it would undo Ben's decision as well. Then name what the board can compare to notice this: the card's version when Asha's move finished, and its version now.
- Follow-ups
-
- The column Asha's card came from is now full. Should her undo go over the limit?
- Should Ben be able to undo Asha's move?
- How long should a person's undo stack be kept?
From the lesson Low-level design: task manager and kanban board
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A team's In progress column has a limit of 5 but holds 9 cards after a CSV import and two people dragging cards in separate browser tabs. Where did the design go wrong, and how do you make the limit hold on every path?
- What it tests
- Rules in the domain rather than the screen, one entry point for changes, checks that cover creates and imports, and concurrent requests against a count.
- First step
- List every way a card can enter the column: a drag in the screen, a create, an import, an API call, an undo. If the limit is checked in the screen, only the first path is covered. Move the check into the board, behind the one method that every path must call, and then ask what happens when two requests arrive together.
- Follow-ups
-
- Two requests for the last free place arrive at the same moment. Which one wins?
- A manager needs to go over the limit during an incident. How do you allow it?
- Should an import fail entirely, or bring in what fits?
From the lesson Low-level design: task manager and kanban board
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Cards are ordered by a floating-point position, and a dropped card gets the midpoint of its neighbours. After many drags, users see two cards swap places on reload. Explain why, then design card order for columns of 5,000 cards.
- What it tests
- Floating-point precision, measuring a failure instead of guessing, the cost of renumbering, and choosing between gapped integers, exact keys and list order.
- First step
- Ask what happens to one gap when cards keep landing in the same place: each drop halves it. Then ask how many halvings a float can take before two neighbours get the same number, and what the database does with a tie. Only then compare the ways to store order by what a drop costs.
- Follow-ups
-
- How often does a column with integer ranks and gaps of 1,024 need renumbering?
- Two people drop cards into the same gap at the same moment. What happens?
- Would fraction strings be better than integers?
From the lesson Low-level design: task manager and kanban board
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A repository holds 2 million files in a directory tree about 6 levels deep, and a commit changes one file. How much does the commit write, and how do you find what changed between it and its parent without reading 2 million entries?
- What it tests
- Content-addressed trees, what one change rewrites along its path, comparing snapshots by skipping equal subtree IDs, and the cost of very wide directories.
- First step
- Follow the changed file up to the root: its blob is new, and so is every tree on its path, because each names the changed one below it. Count them. Then ask what two trees with the same ID tell a comparison of the two commits.
- Follow-ups
-
- One directory holds 100,000 files. What does each commit in it cost now?
- The file is edited back to an older version in the next commit. What is written?
- How would you find the last commit that changed this file?
From the lesson Low-level design: mini version control
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Users delete branches and abandon experiments, and the object store keeps growing. Design garbage collection: which objects may be deleted, and what protects a commit made a minute ago on a detached HEAD, or a branch deleted by mistake?
- What it tests
- Reachability from refs as the liveness rule, marking and sweeping the object graph, a log of past ref values, grace periods, and races with writers.
- First step
- Define live first: an object is live when a branch, a tag, HEAD, the index or a recent entry in a log of past ref values reaches it through commit, tree and blob links. Everything else is garbage, but only after a grace period, because a writer may be about to name a new object.
- Follow-ups
-
- A commit is being written while the collector runs. What can go wrong, and how do you prevent it?
- A user deleted a branch yesterday. How do they get it back?
- How long should the grace period be, and what does it cost?
From the lesson Low-level design: mini version control
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Two long-lived branches, main and release, have merged each other several times. Merging release into main now finds two best common ancestors. Explain how that happens, and what your design does instead of picking one at random.
- What it tests
- Best common ancestors in a graph, criss-cross histories, why a time-based or random choice is unsafe, and merging the bases into one tree first.
- First step
- Draw the smallest history that produces it: main and release each make a commit, then each merges the other's commit. Show that neither commit descends from the other, so both are best common ancestors, and say what a three-way merge needs: exactly one base.
- Follow-ups
-
- Why not take the one with the newest commit time?
- How does merging the bases first work, and what if that merge conflicts?
- How would you test the merge-base code?
From the lesson Low-level design: mini version control
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Twenty minutes after a wicket alert went to every subscriber, the scorers find that the ball on which Esha was bowled was a no ball, so she is not out. Your design keeps the scorecard as running totals. What breaks, and how do you redesign it so that a correction is routine?
- What it tests
- Seeing how far one delivery reaches into derived figures, keeping a log of deliveries as the truth, and publishing a correction that every subscriber can apply.
- First step
- List what the wrong ball changed: the wicket count, Esha's line, the fall of wickets, the bowler's wickets, the next batter's figures, the no-ball penalty and the over's count of valid balls. Then ask what would make all of them move together when one delivery is fixed.
- Follow-ups
-
- The next batter has already faced 9 balls.
- The alert cannot be unsent.
- Two scorers disagree about the ball.
- How do you test corrections?
From the lesson Low-level design: live cricket scorecard
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
In a club match the umpire lets an over run to seven valid balls, and the batter is out off the seventh. Your scoring app ends an over after counting six valid balls. What does it show, what should it show, and what do you change?
- What it tests
- Knowing that the umpire's count is final, recording observed facts instead of deriving them, and turning rules the program cannot enforce into warnings.
- First step
- Read Law 17.5.1: the over as counted by the umpire stands. Then follow the seventh ball through an app that counts to six: which over does it land in, whose figures get the wicket, and what happens to every later delivery?
- Follow-ups
-
- The umpire ends an over after five valid balls.
- The bowler of the next over is the same one, by mistake.
- Overs of 5 balls in another format.
From the lesson Low-level design: live cricket scorecard
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Your live score app shows 183/4 while the ground shows 176/4. Updates reach phones through a message queue that delivers at least once. Find the cause, and fix it without making the publisher slower.
- What it tests
- Recognising duplicated deltas, making updates idempotent with full state and a version, and handling corrections and slow clients.
- First step
- Compare the two scores: 7 runs too many, the same wickets. A queue that delivers at least once repeats some messages, so ask what the app does with each update. If it adds the runs, every duplicate adds them again.
- Follow-ups
-
- Updates arrive out of order.
- A correction lowers the total.
- A phone was offline for an over.
From the lesson Low-level design: live cricket scorecard
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Customers report getting the same shipping SMS twice, a minute apart, on days when the SMS provider is slow. Explain the cause, then fix it without losing any messages.
- What it tests
- Seeing a retry after a lost reply as the cause, idempotency keys honoured by the provider, keeping retries for temporary failures, and why a dead letter may have been delivered.
- First step
- Ask what the service saw for the first attempt. On a slow day the provider can deliver a message and then answer too late, so the service records a timeout and tries again. The fix cannot be "retry less", because real failures then go undelivered; the second attempt must be recognisable as the same message.
- Follow-ups
-
- The provider has no idempotency support. What can you do?
- Should the key be the notification id, or the notification id and the channel?
- A dead letter turns out to have been delivered. How should replays work?
From the lesson Low-level design: notification service
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
Product asks for quiet hours from 21:00 to 08:00 for every user worldwide, and a cap of three promotions a day. Design both, and decide what happens to sign-in codes, order updates and promotions that arrive during quiet hours.
- What it tests
- Rules evaluated in each user's own time, windows that cross midnight, stated exemptions with reasons, and caps counted by the user's calendar day.
- First step
- Fix whose clock the rule uses: the user's, from their time zone, not the server's or UTC. Then write the window as a rule that crosses midnight, and decide each kind's policy with a reason before any code: a code someone just asked for cannot wait until morning.
- Follow-ups
-
- A user in India gets a promotion at 21:15 local time. How could that happen?
- Does a promotion held overnight count towards yesterday's cap or today's?
- A user flies from Delhi to London. Which quiet hours apply?
From the lesson Low-level design: notification service
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Every few days the SMS provider is down for about 30 seconds, and each time a few hundred notifications end up as dead letters. Size a retry policy that rides out such outages, and say what the dead-letter list is for.
- What it tests
- Backoff with jitter sized from the outage's length, the cost in delay, retry ceilings, and dead letters as a work queue with replays that cannot duplicate.
- First step
- Add up the waits the current policy allows. If its attempts and delays add up to less than 30 seconds, every delivery that fails at the start of an outage exhausts its attempts inside it. So the policy must be sized so that its waits, on average, outlast the outages you see.
- Follow-ups
-
- How long do six attempts with limits doubling from 4 seconds wait, at most and on average?
- The provider comes back with 10,000 deliveries waiting. What protects it?
- Who handles a dead letter, and how?
From the lesson Low-level design: notification service
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A candidate's connection drops for the last 4 minutes of a 30-minute section. On reconnecting, the browser replays 9 queued saves: two are for the same question and arrive out of order, and all were made before the deadline by the browser's clock. What does the server keep, and why?
- What it tests
- Idempotent saves with revisions, the server's clock as the only judge of deadlines, and a written policy for answers queued during an outage.
- First step
- Name the two keys of every save: the question and the revision the browser increments. Then say which clock decides the deadline: the server's, never the time a browser attaches. Apply both rules to the nine saves before discussing whether the policy is fair.
- Follow-ups
-
- Two servers receive the two saves in opposite orders. What does the database do?
- The browser's clock is 5 minutes slow. What changes?
- How does the candidate learn which answers counted?
From the lesson Low-level design: online exam with negative marking
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
After the exam closes, one question turns out to have two right options, and the exam's owners decide to accept both for everyone. How do you score 200,000 attempts again and publish ranks that anyone can reproduce?
- What it tests
- Results as a pure function of key, scheme and stored answers, versioned keys, exact arithmetic, and proving that only the intended attempts changed.
- First step
- List what a result depends on: the exam's version, the key, the marking scheme and each attempt's saved answers. If all four are stored, scoring again is the same function with a new key version, not a patch to the totals.
- Follow-ups
-
- Some candidates lose places. What do you publish?
- The question is dropped instead. What changes?
- How do you prove that nothing else changed?
From the lesson Low-level design: online exam with negative marking
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to senior
A numeric question's key is 2.35 with a tolerance of 0.05, so 2.30 and 2.40 must both be accepted. Your implementation accepts 2.40 and rejects 2.30. Explain why, and design the check you would ship.
- What it tests
- Binary floating point and decimal input, validation at save time, absolute and relative tolerances, and the edge cases a test should pin down.
- First step
- Write out the two differences as the code computes them, in binary floating point, before changing anything: one lands just under 0.05 and the other just over it. Then ask what the candidate actually typed, a decimal string, and keep it exact.
- Follow-ups
-
- The candidate types 2.3 instead of 2.30. Is it right?
- The key is 1/3. How do you store it?
- Should scientific notation be accepted?
From the lesson Low-level design: online exam with negative marking
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
All Low-Level Design (Object-Oriented Design) interview questions · The Low-Level Design (Object-Oriented Design) track