Trade-offs and a step-by-step approach for design rounds
40 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)A friend reads your ShopLite plan and asks: "Why a cache? Why not three more servers?" "It is faster" is not enough of an answer. Every choice has a cost, and you must be able to say it.
Your turn: the database is unreachable
On sale day ShopLite cannot reach its database for one minute. Before you read on, decide on paper:
- Do customers keep ordering from the old stock count, or are they asked to retry? Why?
- Would you choose the same for a news feed that cannot reach its database? Why or why not?
- Write your choice as one sentence with its cost: "We chose ..., we gave up ..., because ...".
Classic trade-offs in backend design
Trade-off means a choice where getting more of one good thing means accepting less of another. Every design decision is one, so a strong answer names what was chosen, what it costs and why that cost is acceptable.
Three trade-offs come up in almost every design round. The first example plays the database-down case from your turn. The second picks the cheapest option that meets a target.
Example 1 · Consistency vs availability when the database is unreachable
public class StockTradeOffDemo { static int realStock = 2; static int cachedStock = 5; static boolean databaseReachable = false;
// Consistent choice: no sale unless the true stock can be checked. static String consistentOrder(String customer) { if (!databaseReachable) { return customer + ": sorry, please try again in a minute"; } return customer + ": order placed"; }
// Available choice: always answer, using the old copy. static String availableOrder(String customer) { if (cachedStock > 0) { cachedStock--; realStock--; // applied later, when the database is back return customer + ": order placed"; } return customer + ": sold out"; }
public static void main(String[] args) { String[] customers = {"Asha", "Bilal", "Charu"};
System.out.println("Choose consistency:"); for (String c : customers) { System.out.println(" " + consistentOrder(c)); }
System.out.println("Choose availability:"); for (String c : customers) { System.out.println(" " + availableOrder(c)); } System.out.println(" Real stock afterwards: " + realStock + " (one phone sold that does not exist)"); }}Choose consistency: Asha: sorry, please try again in a minute Bilal: sorry, please try again in a minute Charu: sorry, please try again in a minute Choose availability: Asha: order placed Bilal: order placed Charu: order placed Real stock afterwards: -1 (one phone sold that does not exist)
What this code does
- The consistent choice refuses every order while the true stock cannot be checked: no wrong sale, but the shop is effectively down.
- The available choice keeps selling from an old count of 5 and sells three phones when only two exist. Which is better depends on the cost of a wrong answer vs the cost of no answer.
Example 2 · Latency vs cost: the cheapest option that meets the target
import java.util.List;
record Option(String name, int p95Ms, int rupeesPerMonth) {}
public class CacheCostDemo { public static void main(String[] args) { List<Option> options = List.of( new Option("No cache, 1 DB", 420, 12_000), new Option("Small cache", 180, 18_000), new Option("Big cache + replica", 90, 45_000));
int targetMs = 300; int budget = 25_000;
Option chosen = null; for (Option o : options) { boolean fast = o.p95Ms() <= targetMs; boolean affordable = o.rupeesPerMonth() <= budget; System.out.printf("%-20s p95 %3d ms Rs %6d/month %s%n", o.name(), o.p95Ms(), o.rupeesPerMonth(), fast && affordable ? "meets both" : (fast ? "too costly" : "too slow")); if (fast && affordable && chosen == null) { chosen = o; } } System.out.println("Cheapest option that meets " + targetMs + " ms: " + chosen.name()); }}No cache, 1 DB p95 420 ms Rs 12000/month too slow Small cache p95 180 ms Rs 18000/month meets both Big cache + replica p95 90 ms Rs 45000/month too costly Cheapest option that meets 300 ms: Small cache
What this code does
- Each option has a p95 latency and a monthly cost. The program keeps the first option that meets both the 300 ms target and the Rs 25,000 budget.
- The big cache is fastest, but paying Rs 45,000 for 90 ms when 300 ms is the requirement buys nothing the users asked for.
Consistency vs availability: when part of the system cannot reach the database, refuse requests (correct but down) or answer from old data (up but possibly wrong). Latency vs cost: caches, replicas and bigger servers make things faster, and each one adds to the bill.
Simplicity vs flexibility: one application is easy to build, test and deploy; many services can change and scale separately, at the price of more moving parts. No side is right in general. The requirements decide, which is why you write them down first.
Predict the output
Pick the option that meets the target
Read the code and pick what it prints.
Target: p95 under 200 ms and a budget of Rs 25,000 a month. Which option do you pick?
Writing a trade-off: we chose X, we gave up Y, because Z
A choice without its cost sounds like a guess. Use one fixed sentence shape: "We chose X; we gave up Y; because Z." The example builds that sentence for four ShopLite decisions.
Example 3 · Every decision as chose, gave up, because
import java.util.List;
record TradeOff(String chose, String gaveUp, String because) { String sentence() { if (gaveUp.isBlank()) { return "INCOMPLETE: \"We chose " + chose + "\" names no cost"; } return "We chose " + chose + "; we gave up " + gaveUp + "; because " + because + "."; }}
public class TradeOffStatements { public static void main(String[] args) { List<TradeOff> decisions = List.of( new TradeOff("one application (monolith)", "separate scaling of each part", "two developers can build and deploy it in a day"), new TradeOff("a 60-second cache on product pages", "prices that are always up to the second", "pages get 4x faster and MySQL load drops"), new TradeOff("rejecting orders when stock cannot be checked", "a few minutes of sales during failures", "overselling a phone costs more than a retry"), new TradeOff("Kafka", "", ""));
for (TradeOff t : decisions) { System.out.println(t.sentence()); } }}We chose one application (monolith); we gave up separate scaling of each part; because two developers can build and deploy it in a day. We chose a 60-second cache on product pages; we gave up prices that are always up to the second; because pages get 4x faster and MySQL load drops. We chose rejecting orders when stock cannot be checked; we gave up a few minutes of sales during failures; because overselling a phone costs more than a retry. INCOMPLETE: "We chose Kafka" names no cost
What this code does
sentence()builds the fixed shape "We chose X; we gave up Y; because Z" for each decision.- The last decision names a tool and no cost, so it is flagged as incomplete. That is how "we will use Kafka" sounds to an interviewer.
X is the option, Y is the honest cost, and Z ties it to a requirement or a number. For example: "We chose a 60-second cache; we gave up prices exact to the second; because pages get 4x faster and a price change can wait a minute." An interviewer can agree or push back on that, which is exactly the conversation they want.
Find the bug
Find the sentence with no cost
Select the line that is wrong.
Which sentence names no cost?
Round 1 of 2The 6-step framework and the 45-minute budget
6-step framework is a fixed order for a design round: clarify, estimate, API, data model, high-level design and deep dive, then a wrap-up of trade-offs. Each step feeds the next.
A fixed order keeps you calm and makes sure nothing big is missed. Here are the six steps and what to produce in each.
1 Clarify features, users, out of scope, NFR numbers2 Estimate requests/second (average, peak), storage per year3 API 3-5 endpoints with method, URL, request, response4 Data model tables or entities and their keys5 High level [Client] --> [LB] --> [App] --> [DB] ...6 Deep dive the hardest part, bottlenecks, failures Wrap-up trade-offs, what changes at 10xEach step feeds the next: the estimate tells you whether one database is enough, the API tells you which data you need, the data model tells you where the hard part is. A time budget says how many minutes each step gets: 5 for each of the first four steps, 10 for the high-level design, 10 for the deep dive and 5 to wrap up.
Example 4 · A 45-minute plan with a sentence to say at each step
import java.util.List;
record Step(String name, int minutes, String sayAloud) {}
public class DesignRoundTimer { static String clock(int minute) { return String.format("%02d:00", minute); }
public static void main(String[] args) { List<Step> steps = List.of( new Step("Clarify requirements", 5, "\"Let me confirm the features and the scale.\""), new Step("Estimate", 5, "\"About 6 searches a second at peak, 50 MB of data.\""), new Step("API", 5, "\"Three endpoints: search, issue, return.\""), new Step("Data model", 5, "\"Books, copies, members, loans.\""), new Step("High-level design", 10, "\"Request flow from the app to the database.\""), new Step("Deep dive + bottlenecks", 10, "\"Two people issue the last copy at once...\""), new Step("Wrap-up", 5, "\"Trade-offs, and what I'd add at 10x.\""));
int now = 0; for (Step s : steps) { int end = now + s.minutes(); System.out.printf("%s-%s %-24s %s%n", clock(now), clock(end), s.name(), s.sayAloud()); now = end; } System.out.println("Total: " + now + " minutes"); }}00:00-05:00 Clarify requirements "Let me confirm the features and the scale." 05:00-10:00 Estimate "About 6 searches a second at peak, 50 MB of data." 10:00-15:00 API "Three endpoints: search, issue, return." 15:00-20:00 Data model "Books, copies, members, loans." 20:00-30:00 High-level design "Request flow from the app to the database." 30:00-40:00 Deep dive + bottlenecks "Two people issue the last copy at once..." 40:00-45:00 Wrap-up "Trade-offs, and what I'd add at 10x." Total: 45 minutes
What this code does
- Each step has a minute budget; the loop prints its start and end time so you know where you should be at minute 20 or 30.
- The quoted sentence is what you say aloud to start the step. Short sentences like these let the interviewer follow and steer.
The budget is a guide, not a script. If you are at minute 22 and still listing requirements, say your assumptions in one sentence and move on. If the interviewer cuts in with another question, follow them.
Order of execution
Put the six steps in order
Tap the steps in the order they happen.
One good design: the library catalogue
Try it first: write the six steps for "Design a library catalogue for our college" on paper. Then compare with this answer, starting with its estimate step in code.
Example 5 · The estimate step of the library walkthrough
public class LibraryEstimate { public static void main(String[] args) { // Step 2 of the walkthrough: assumptions said aloud int students = 5_000; int searchesPerStudentPerDay = 2; int examWeekFactor = 10; int books = 50_000; int bytesPerBook = 1_000; int loansPerDay = 400; int bytesPerLoan = 100;
int searchesPerDay = students * searchesPerStudentPerDay; double peakSearchesPerSecond = searchesPerDay * examWeekFactor / 86_400.0 * 5; // busiest hour ~5x the day's average double catalogueMb = books * (double) bytesPerBook / 1_000_000; double loansMbPerYear = loansPerDay * 365.0 * bytesPerLoan / 1_000_000;
System.out.println("Searches per day: " + searchesPerDay); System.out.printf("Peak searches/second: %.1f (exam week, busiest hour)%n", peakSearchesPerSecond); System.out.printf("Catalogue size: %.0f MB%n", catalogueMb); System.out.printf("Loan history per year: %.1f MB%n", loansMbPerYear); System.out.println("Verdict: one app server and one MySQL database are plenty"); }}Searches per day: 10000 Peak searches/second: 5.8 (exam week, busiest hour) Catalogue size: 50 MB Loan history per year: 14.6 MB Verdict: one app server and one MySQL database are plenty
What this code does
- Written assumptions give about 6 searches a second at the busiest hour of exam week and a 50 MB catalogue.
- Small numbers are a valid result: they justify a simple design, and saying so with numbers is stronger than adding servers "to be safe".
Clarify: students search books and see free copies; librarians issue and return; out of scope: e-books. API: GET /books?q=, POST /loans, POST /loans/{id}/return. Data model: books, copies, members, loans.
High level: [Phone] --> [App server] --> [MySQL], since the numbers are small. Deep dive: two students issuing the last copy at the same moment, solved with a transaction that checks the copy is still free. Wrap-up: "We chose one server; we gave up surviving a server crash; because the library can issue on paper for an hour, and one server costs a fraction of two."
Next step
Check your understanding
11 quick questions