All jobs / Backend developer / Distributed Systems
Backend developer interview question · 5+ years
The interviewer asks: “We're adding a search index. Can the API write DB and Elasticsearch in one request?” Strongest answer?
The strongest answer
That's a dual write — one will fail. I commit to the database (and outbox) and let a consumer update search, or I use change-data-capture. I don't require both commits in the request.
Why it works
Exactly. Search is a derived view. The system of record commits first; search catches up. Idempotent upserts handle the lag.
What a good answer covers
- System of record first.
- Derive search via outbox or CDC.
- Don't dual-commit in the request.
- Don't 2PC the search engine.
Answers that fall short
- Close, but not the strongest: Write both and ignore search errors so checkout is fast.
Ignoring search errors means the index silently diverges. Users won't find orders that exist. That's an ops problem you'll page on. - Weak: Write search first so the UI is snappy, then the DB.
Search-first creates documents for rows that roll back. Now you delete — if you remember. - Red flag: A distributed transaction across Postgres and Elasticsearch.
2PC with a search engine is not a thing you want to operate. Outbox/CDC is the pattern.
Who gets asked this
More Distributed Systems questions
- What happened, and what actually protects the write?
- The interviewer asks: “Active-active in two regions — what's the hard part?” Strongest answer?
- The interviewer asks: “A client retries POST /payments because of a timeout. How do you not charge twice?”…
- The interviewer asks: “A downstream HTTP call timed out. Do you retry?” Strongest answer?
- The interviewer asks: “Your HTTP client has no timeout. What's the risk?” Strongest answer?
- A RabbitMQ consumer acknowledges each message as soon as it arrives and then processes it. Messages go…
- The interviewer asks: “Your queue consumer ran twice for the same message. What do you do?” Strongest answer?
- What do you tell them, and what does it force on your code?