Backend interview questions with sample answers
For backend interviews, start by stating what the system must guarantee. Explain who owns the data, what happens when a request is retried or a dependency fails, and which metric would show the design is working.
How would you publish an event after a database commit?
Write the business record and an outbox entry in the same transaction. A worker publishes the entry and marks it sent after the broker acknowledges it. The worker may crash between publishing and marking it sent, so consumers process a stable event ID idempotently. Measure outbox age and retries as well as the publish rate.
Follow-up · How do you make an irreversible external side effect idempotent?
How do you keep cached data fresh?
Start with the allowed staleness. For a catalog where a brief delay is fine, use cache-aside with a TTL and invalidate on writes where needed. Add a jittered expiry or request coalescing for hot keys. Read balances and authorization data from an authoritative source if the allowed staleness is zero.
Follow-up · What if a concurrent reader repopulates the cache with stale data just after invalidation?
When would you use cursor pagination?
For a frequently updated feed, paginate on a stable ordering such as created_at and id. Fetch rows strictly after the last pair and index that order. It avoids the work of skipping a large offset and keeps page boundaries stable when newer rows arrive. An export that needs a fixed snapshot requires an explicit snapshot or cutoff.
Follow-up · What breaks if the ordering column can change between requests?
Practice out loud
Explain the outbox design aloud in 90 seconds, then draw the failure window between publish and acknowledgement.
Start a free mock interview