Engineering Decisions Middle cheat sheet: interview answers
Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.
1. A news feed serves 1M users, may lag by a minute, and every call to the upstream API is paid. What's the main approach?
Correct answer: A shared server cache with a TTL of about 60 seconds
One shared entry means all users cost a single upstream call per minute, and the minute of lag is allowed. A browser cache fits personal data and saves repeat visits, but with 1M users each one still pays for an upstream call. Fetching on every visit fits data that must be exact, like a balance, and here it would multiply the bill for no benefit.
2. After a transfer, the user opens their balance. The number must be exact, while the rest of the banking app reads from replicas. Where does this read go?
Correct answer: To the primary, with no cache in between
Money shown right after a write must reflect that write, and the primary is the one place that guarantees it. A replica fits lists and history, where a second of lag is harmless. A cache with invalidation fits frequently read data with rare writes, but a missed invalidation here would show a wrong balance, which costs more than the extra read.
3. You're publishing an API for external partners who use many languages. Responses should work with CDNs, and a partner's first call should take minutes. Which style?
Correct answer: REST over HTTP with an OpenAPI description
REST needs nothing beyond an HTTP client, and GET responses work with CDNs out of the box. GraphQL fits clients with very different data needs, though caching usually takes more work because queries often go by POST. gRPC fits fast internal calls between services you control, but it needs generated clients and doesn't work directly from a browser.
4. Web and mobile apps need very different data from the same services. Each client has its own team, and mobile suffers from large payloads. What do you add?
Correct answer: A separate BFF owned by each client team
A BFF lets each team shape responses for its own screens and release without waiting for others. A
?fields=parameter fits small differences in one resource, but it won't aggregate several services for a screen. Direct calls fit a very small system, while here they would add round trips on mobile and expose the internal service layout.5. A sports site pushes live scores to browsers. Data flows only from the server, traffic passes through regular HTTP proxies, and reconnects must be simple. What fits?
Correct answer: Server-Sent Events over plain HTTP
Server-Sent Events are made for one-way streams, run over ordinary HTTP and reconnect automatically. WebSockets fit two-way traffic like chat or games, but here they add a protocol and reconnection logic for a direction nobody uses. Short polling fits rare updates, whereas every two seconds it means a lot of empty requests at this scale.
6. A payment request timed out, so you don't know whether the charge went through. Charging twice is unacceptable, but the sale shouldn't be lost. What do you build?
Correct answer: Safe retries with one idempotency key per payment
With a key, the provider treats the retry as the same operation, so it can't charge twice even if the first call succeeded. Showing an error fits actions that are cheap to repeat, but the user may pay twice by pressing the button again. Checking first fits providers that have no keys, yet it leaves a race: the first charge may still be in flight during the check.
7. Checkout calls a recommendations service that sometimes hangs for 30 seconds. Recommendations are optional, while checkout must stay fast. What do you do?
Correct answer: A short timeout with a fallback of no recommendations
An optional feature should never hold up the main flow, so a short timeout and an empty fallback keep checkout fast. Long timeouts with retries fit a dependency you truly can't work without, and here they would stack delays on top of a hanging service. Merging the services fits two parts that always change together, but it's a big rewrite and doesn't fix the slowness itself.
8. A sales dashboard runs a 40-second aggregation on each load. Managers open it a few times a day, and data from the last hour is enough. What's the fix?
Correct answer: A materialized view refreshed every hour
Precomputed results load instantly, and hourly freshness is exactly what the managers need. A replica fits heavy reads that must be near real time and protects the primary, but the page would still take 40 seconds. Emailed reports fit people who want a digest, and they would replace an interactive dashboard that is used directly.
9. An activity log has 50M rows, and
OFFSETgets slower on deep pages. The UI only has "Older" and "Newer" buttons. How do you paginate?Correct answer: Keyset pagination on
(created_at, id)Keyset pagination seeks through an index, so depth doesn't affect speed, and next/previous buttons are all it needs. Caching fits a list that rarely changes, but a log grows constantly, so cached pages shift. A depth cap fits search results, where nobody goes deep, while here it would hide old records that people may need.
10. A web app talks to its own API on the same domain. Support must be able to end a stolen session immediately. How do you handle sessions?
Correct answer: Server sessions with an
HttpOnlycookieWith sessions on the server, deleting the record ends access at once, and an
HttpOnlycookie stays out of reach of scripts. JWTs inlocalStoragefit almost nothing here: an XSS bug can read them, and they can't be revoked. Short-lived JWTs fit many independent services that verify tokens on their own, but a stolen token stays valid until it expires, unless you add a revocation list.11. Checkout's p99 latency doubled. A request passes through six services, and logs don't show which one is slow. What do you reach for?
Correct answer: Distributed tracing across the request's path
A trace shows one request's time in every service, so the slow step is visible at once. More logs fit a failure inside one known service, but matching them across six needs a shared ID and much more work. Host dashboards fit resource problems, while a slow query or a lock can hide behind perfectly normal CPU.
12. On-call engineers get dozens of alerts a night, and most need no action. Users, meanwhile, sometimes notice outages first. What do you alert on?
Correct answer: Burn rate of a user-facing SLO
An SLO alert fires when users are actually affected and the error budget is melting, so a page means real work. CPU alerts fit capacity planning as a dashboard or a ticket, but high CPU often harms nobody. Alerting on every error line fits a brand-new service for a short time, and at scale it recreates the noise you're trying to remove.
13. A rewritten pricing engine may fail only under real traffic. A bug would be costly, so you want to limit how many users it can reach. How do you release it?
Correct answer: A canary: 1% of traffic, growing as metrics stay healthy
A canary limits the damage to a small share of users and shows real behavior before everyone is exposed. Blue-green fits fast, clean rollbacks, but every user gets the new code at the same moment. A night release fits changes that need downtime, yet low traffic may hide the very bug you're worried about.
14. A "like" button should feel instant on slow mobile networks. A rare failure isn't harmful and can simply be undone. How do you update the UI?
Correct answer: Optimistically, rolling back if the request fails
An optimistic update shows the result at once, and a likes counter can safely roll back on the rare failure. Waiting for the server fits operations where a wrong result hurts, such as payments. Refetching fits data that changes on the server in ways you can't predict, but here it adds a delay and a heavy request per click.