An order flow touches your database, a payment provider and an email service. How do you keep the system consistent when any step can fail?
What the interviewer wants to hear
- No single transaction across external systems
- Idempotency keys for retries with the payment provider
- Transactional outbox for reliable events
- Saga style steps with compensating actions
- Webhooks verified and processed idempotently; reconciliation jobs
Model answer
I accept that there is no single transaction across my database, the payment provider and email, so I design for retries and partial failure. I model the order as a state machine: pending, paid, confirmed, failed. Creating the order and a pending payment record happens in one database transaction. Calls to the payment provider use an idempotency key, so a retry after a timeout cannot charge twice. The provider tells me the final result through a webhook, which I verify by signature and process idempotently, because webhooks can arrive late, twice or out of order. When the order becomes paid, I write an event to an outbox table in the same transaction, and a worker sends the email with at-least-once delivery. If a later step fails, I run a compensating action such as a refund, saga style. Finally, a daily reconciliation job compares my records with the provider to catch anything missed.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Full Stack Developer questions
- You are building a multi-tenant B2B SaaS app. How would you design data isolation between tenants, and what are the trade-offs?
- Your app works well for 1,000 users. Traffic is expected to grow to 1 million users. How would you prepare the system, and in what order?
- You need to split a large users table column "name" into "first_name" and "last_name" on a table with 50 million rows, with no downtime. Walk through your plan.
- For a large e-commerce site in Next.js, how would you choose the rendering and caching strategy for the home page, product pages, cart and account pages?
- Design an e-commerce checkout end to end: cart, payment with a provider like Stripe, inventory and order confirmation. What can go wrong and how do you make it reliable?
- Your startup’s Next.js monolith is growing and some engineers want to split it into microservices. How do you decide, and what would you do?
- Ten minutes after a deploy, 500 errors jump from 0.1% to 8% on the main API. Walk through how you handle the incident.
- Customers need to import CSV files with up to two million rows into your app. Design the feature end to end.
- You are opening your product’s API to outside partners. How do you design authentication, authorization, rate limiting and change management for it?