Skip to content
notes.vinhnq.com

Search

System DesignSenior18 min read

Analysing trade-offs like a senior: ideality, sweet spots, coupling and separation

Review 15 cards
On this page

Problem solving and trade-offs series: 1. Problem solving · 2. Analysing trade-offs

Once you understand the problem, you usually have several solutions, each good in some ways and bad in others. This post shows how to score options, when to settle on a balance point, when you can “break” a trade-off by separating components, and how to present it like a senior. Part 1, Problem solving like a senior, covers defining problems; the one idea to carry over is that a problem is the gap between the reality a stakeholder perceives and the reality they expect, closed by changing reality, changing perception or adjusting the expectation.

At a glance:

flowchart TD
  A["Agree top 3 dimensions"] --> B["List the alternatives"]
  B --> C["Score with Ideality"]
  C --> D{"How to resolve?"}
  D -->|"Pick a point"| E["Sweet spot on curve"]
  D -->|"Redesign"| F["Remove the coupling"]
  F --> G["Push curve toward origin"]
  E --> H["State what you trade"]
  G --> H

1. What is a trade-off?

Key idea: a trade-off appears when there are several solutions and each is good on some dimensions and bad on others. Without trade-offs you wouldn’t need a senior engineer, just a lookup table.

1.1 The dimensions depend on context

Key idea: “best” always means best on the dimensions your context cares about, so the first step is to agree with the stakeholders on the top three dimensions and their order.

Context Dimensions usually prioritised
Startup searching for product-market fit Speed of delivery (agility), cost
Large enterprise, bank Reliability, security, scalability, compliance
B2C product with many users Performance, reliability

Arguments drag on not because anyone is wrong, but because the two sides silently prioritise different dimensions. These dimensions are quality attributes, one of the four groups of architectural drivers that pull on each other in Pragmatic software architecture: architectural drivers.

1.2 Dimensional and alternative trade-offs

Key idea: dimensional trade-offs are between quality attributes (problem space); alternative trade-offs are between concrete options (solution space). Picking an option places you at a point on the curve between attributes.

  • Dimensional: security vs performance (encryption, authenticating every request), scalability vs cost, polished UI vs power and flexibility, consistency vs availability.
  • Alternative: SQL vs NoSQL, monolith vs microservices, OOP vs FP, Kafka vs RabbitMQ.

For example, choosing microservices trades operational simplicity for independent deployment and scaling. So when you present, don’t just say “I chose Kafka”. Say “I prioritised throughput and replayability over low latency and simplicity, so I chose Kafka”.

1.3 The ideality formula

Key idea: TRIZ (a Soviet method for inventive problem solving) scores options with Ideality = Σ Benefits / (Σ Resources required + Σ Harmful effects). It forces you to look at the denominator, not just the benefits.

  • Benefits: gains on each dimension (lower p99, lower cost, higher reliability).
  • Resources: money, people, time, operational complexity.
  • Harmful effects: bad consequences (stale data, one more point of failure, vendor lock-in, security risk). List them with Seven-So-What: ask “we do that, so what?” a few times for each option.

The ideal solution delivers the benefit while costing and harming almost nothing. Example: two elevators overloaded at rush hour. “Widen the clock-in window” has higher ideality than “install another elevator” despite a smaller benefit, because its denominator is close to zero.

An ideality scoring example: the slow order list page

Scores 1–5, weighted by the agreed priorities:

Option Benefit Resource Harm Notes
A suitable index + keyset pagination 4 1 1 Highest ideality, if the query plan confirms it
Redis cache for the first page 3 2 3 Stale data, one more system, tricky invalidation
Read replica 3 3 2 Replication lag, machine cost
Move to Elasticsearch 5 5 4 Data sync, an entire extra stack

The numbers are just a device to make people state their assumptions. The real value is the discussion about why Redis’s harm is a 3 and not a 1.

1.4 Pick a sweet spot or resolve the trade-off

Key idea: the options sit on a curve (the Pareto front: improve X and Y gets worse). Either pick the point that fits your context (a sweet spot), or find a new design that pushes the whole curve towards the origin, where nothing is bad.

  1. Pick a sweet spot: a 60-second cache TTL balances database load against freshness.
  2. Resolve the trade-off: instead of choosing a TTL, use CDC (change data capture, reading the binlog/WAL to learn which rows just changed) to invalidate almost immediately. Low database load and fresh data.

2. Traps when discussing trade-offs

Key idea: the two big traps are seeing only the benefits of the option you like, and underestimating the harm of things you’ve never operated.

Seeing only one side. Rich Hickey: programmers know the benefits of everything and the trade-offs of nothing. Neal Ford and Mark Richards call it the first law of software architecture: everything is a trade-off; if you think you’ve found something that isn’t, you just haven’t identified the trade-off yet.

Underestimating the unknown. New technology has harmful effects nobody on the team has hit yet: early-version bugs, thin documentation, a small hiring pool, missing monitoring tools. That’s the reasoning behind the boring technology movement: every company has only a few “innovation tokens”, so spend them on what differentiates you and use boring tools, whose failure modes are well understood, for everything else.

Boring or new technology: a rule for choosing

3. Coupling: the root of many trade-offs

Key idea: many trade-offs exist because two things that should be independent are tied together (coupling). Separate them and each side optimises for its own dimension, so the trade-off disappears or shrinks a lot.

  • Reads and writes share one model: optimising for reads (denormalising, lots of indexes) hurts writes, and vice versa.
  • Business logic mixed with I/O: fast tests are hard, changing the database is scary.
  • Every service handles its own TLS, retries and metrics: changing a security policy means redeploying every service.

TRIZ systematises separating as separation principles:

Principle Everyday example Software example
Separation in time An umbrella folds when not in use and opens in the rain A startup prioritises agility and cost first, reliability and security later, phase by phase; feature flags; batch at night, real time by day
Separation in space A multi-tool: a knife at one end, a hammer at the other Sidecar: TLS, retries and metrics in a process next to the app; separating hot data (cache) from cold data (archive)
Separation between parts and the whole A bicycle chain: each link is rigid, the chain is flexible Functional core, imperative shell: a pure, immutable, easily tested core; a thin shell that handles I/O and state
(Extension) Separation on condition Glasses that darken in sunlight CQRS: a normalised write model, a denormalised read model, each optimised separately
Two trade-offs of separating: CQRS and sidecars

3.1 Functional core, imperative shell in Java

Key idea: separate the pure calculation (the functional core: input in, output out, no I/O) from the database calls, transactions and clock (the imperative shell). The core is tested with millisecond unit tests; the thin shell needs only a few integration tests.

Example: pricing a booking. The tangled version reads the clock, calls repositories and does the maths in one method, so testing the discount needs a database. Pull the core out:

// Functional core: pure, no I/O, no system clock
record Quote(long nights, long subtotal, long discount, long total) {}

final class Pricing {
    static Quote quote(List<Long> nightlyPrices) {
        long subtotal = nightlyPrices.stream().mapToLong(Long::longValue).sum();
        long discount = nightlyPrices.size() >= 3 ? Math.round(subtotal * 0.05) : 0;
        return new Quote(nightlyPrices.size(), subtotal, discount, subtotal - discount);
    }
}

// Imperative shell: handles I/O, transactions, the clock
@Service
@RequiredArgsConstructor
class BookingService {
    private final AvailabilityRepository availability;
    private final BookingRepository bookings;
    private final Clock clock;

    @Transactional
    public Booking book(BookingRequest req) {
        List<Long> prices = availability.lockNightlyPrices(req.homestayId(), req.checkin(), req.checkout());
        Quote quote = Pricing.quote(prices);              // call the core
        return bookings.save(Booking.from(req, quote, clock.instant()));
    }
}

Pricing.quote is tested with a few lines of JUnit, no Spring needed; the “fast tests vs realistic tests” trade-off is partly resolved. Note the fields are final: with @RequiredArgsConstructor, a non-final field isn’t part of the constructor and never gets injected.

4. Applying it in system design interviews

Key idea: clarify, break down, propose the simplest design, then for every decision say what you trade for what. Whenever you move to a new part, state the conclusion first (top-down).

  1. Clarify the problem (5–10 minutes, see part 1): who uses it, for what, at what scale (QPS, data volume, growth), and which dimension matters most (latency, consistency, cost). State your assumptions out loud.
  2. Break it down: the main flows, and which part is hardest (usually concurrent writes, consistency, hot spots).
  3. Propose the simplest design that works, then evolve it around the bottlenecks.
  4. For every decision: two options, which you pick, what it costs, when you’d switch. Check yourself with five questions:
    • order: is ordering needed;
    • duplication: what if it runs twice;
    • relationship: who owns the data;
    • direction: who depends on whom;
    • consistency: sync or async, and how much lag.
  5. Finish with risks and next steps: what’s still weak and what you’d measure to validate it.

The four-step process and how to turn requirements into numbers (DAU, QPS, p99) are in The system design interview: process and requirements; the foundational trade-offs such as CAP, PACELC, p99 and MTTR are in Design principles: CAP, scalability, performance and availability.

Exercises

Exercise 1: Score options with ideality

Task (paraphrased): A booking service must send an event to a notification service. Three options: (a) a synchronous HTTP call inside the transaction, (b) publishing to Kafka after the commit, (c) an outbox table plus a relay. Score benefit / resource / harm and choose.

Solution to Exercise 1: HTTP, Kafka or outbox
Option Benefit Resource Harm Reason
(a) Synchronous HTTP 2 1 5 A slow or dead notification service breaks booking; if the transaction rolls back after the call, the notification is wrong
(b) Kafka after commit 4 3 3 A crash between commit and publish loses the event
(c) Outbox + relay 5 3 1 The event is written in the same transaction; the relay can resend; consumers must be idempotent and the outbox table needs cleaning

Pick (c) if the notification matters (payment confirmation); (b) can be acceptable for “nice to have” notifications. Check it against the checklist too: Duplication (the relay may resend, so consumers must dedupe), Order (use booking_id as the key if per-booking ordering matters).

Exercise 2: Apply a separation principle

Task (paraphrased): A product detail page must (1) read extremely fast at 20,000 QPS and (2) have exact stock when an order is placed. With one model and one table, the two requirements pull in opposite directions. Use a separation principle to resolve it.

Solution to Exercise 2: separate display from ordering

Separate between parts and the whole, or on condition:

  • The “display” part (name, description, images, approximate stock) is served from a cache or read model and may lag by a few seconds.
  • The “order” part checks stock on the primary database with a conditional update: UPDATE stock SET qty = qty - 1 WHERE sku = ? AND qty > 0.

Users may occasionally see “in stock” and then fail to order, so change the perception too: show “almost gone” when stock is low and give a clear message when the order fails. The fast-reads-vs-exactness trade-off is resolved by not asking one place to do both.

Remember

  • Explain why you settle the top three dimensions and their order before scoring options.
  • Tell dimensional from alternative trade-offs, and describe a technology choice by the attributes it prioritises.
  • Write down the ideality formula and explain why the denominator matters.
  • Know when to pick a sweet spot and when to invest in resolving the trade-off, with an example (TTL vs CDC).
  • Name the four separation principles with a software example each, and the new trade-offs separating brings.

Interview questions

Junior

What is a trade-off? Give a backend example.

A trade-off is when improving one aspect means accepting something worse in another.

Caching, for instance: reads get faster and the database gets lighter, but data can be stale until the TTL expires and there’s one more system to run. Or an index: faster reads, but slower writes and more storage.

Mid

How do dimensional and alternative trade-offs differ?

Dimensional trade-offs are between quality attributes (problem space); alternative trade-offs are between concrete options (solution space).

Dimensional: security vs performance, consistency vs availability, scalability vs cost. Alternative: SQL vs NoSQL, monolith vs microservices. Choosing an option places you at a point on the curve between attributes, so when presenting, state the attributes you prioritised before naming the technology.

Why do many teams choose “boring technology”?

Because familiar technology has known failure modes, while the harms of new technology usually aren’t in the comparison table because nobody has hit them yet.

Familiar technology comes with documentation, tooling and people you can hire. A company only has a few “innovation tokens”, so spend them on what differentiates the product. It doesn’t mean never using anything new, but there should be a clear reason, an owner to run it and a way back.

Senior

Two seniors on your team disagree on Kafka vs RabbitMQ. How do you handle it?

Agree on the top three attributes for this use case first, because the disagreement usually comes from silently different priorities; then score, measure and write an ADR.

  • Example attributes: per-key ordering, replay, latency, operational simplicity.
  • Score each option on those attributes and list the harmful effects. If the argument is about numbers, run a PoC with realistic load.
  • Record the decision in an ADR with the rejected option and the conditions for revisiting it.
  • Still disagreeing: the accountable person (tech lead, architect) decides and the team disagrees and commits.
Give an example of a trade-off you “resolved” rather than just picking a balance point.

Cache invalidation: instead of choosing a long or short TTL, use CDC on the WAL/binlog to evict cache entries as soon as data changes, keeping a long TTL as a safety net.

A long TTL means a light database but stale data, a short one the opposite; CDC gives both. Another example: CQRS separates the read and write models so each is optimised on its own. How to tell it: name the coupling that caused the trade-off, how you separated it (in time, in space, parts vs whole), and the new harmful effects the design brought (a CDC pipeline to monitor, eventual consistency).

How does the TRIZ ideality formula help you choose an option?

Ideality = total benefits / (total resources + total harmful effects); it forces you to look at the denominator.

An option with a moderate benefit that costs and harms almost nothing (moving a batch job, adding an index) often beats one with a big benefit that adds a whole system. The numbers aren’t precise; the value is that everyone has to state their assumptions about cost and harm, especially long-term operational cost.

Which trade-off does functional core, imperative shell resolve?

The one between fast, easy-to-reason-about tests and the need to do I/O, transactions and read the clock.

The core holds only pure logic (input → output, no side effects), tested with millisecond unit tests. The thin shell handles I/O and calls the core, so it needs only a few integration tests. It’s separation between parts and the whole: each part is rigid (pure, immutable), while the whole can still do stateful work. In Spring: records and static methods for the calculations, a @Service that only orchestrates, and an injected Clock instead of calling now() inside the core.

In a system design interview, how do you talk about trade-offs convincingly?

Top-down: the conclusion first, then the attributes you prioritised, the price you accept, the failure modes, and the condition that would change the decision.

For example: “I’d pick X because A and B matter most here; in exchange, C; if QPS goes past N, I’d move to Y.” Always mention at least one rejected alternative and why. Never claim “no downsides”, and state your assumptions so the interviewer can change one and see how you adapt.

Useful phrases for interviews

  • “Before comparing options, can we agree on the top three things we’re optimising for?”
  • “I’d prioritise throughput and replay over latency here, which is why I’m leaning towards Kafka.”
  • “The trade-off is fresher data in exchange for more load on the database.”
  • “This option has the best ideality: a moderate benefit, and it costs us almost nothing to run.”
  • “Rather than picking a TTL, we can resolve the trade-off by invalidating from the change stream.”
  • “The root of this trade-off is coupling between the read and write paths, so I’d separate them.”
  • “I’d default to boring technology here; this isn’t where we differentiate.”
  • “If traffic grows past ten thousand requests per second, I’d revisit this decision.”
  • “Let me be explicit about the downside: we accept eventual consistency on the listing page.”

Notes based on the Advanced Backend course (Ronin Engineer), rewritten in my own words.