Order service and inventory service need to stay consistent. Walk through your options.
Microservices interviews almost always include this. The interviewer wants you to weigh consistency vs availability vs implementation cost — not just name "2PC".
2PC/XA: strongly consistent but blocking and fragile on coordinator failure. Rarely used in internet companies today.
TCC (Try-Confirm-Cancel): business-level 2PC. You write three methods per operation. Strong consistency, but big code cost and idempotency discipline.
Saga: chain of local transactions with compensating actions on failure. Works at any scale but only eventually consistent, and compensations are business logic.
Local message table / transactional outbox: write business change + message in the same local transaction, separate process relays the message. The pragmatic default for most systems.
Seata is the popular Java framework — AT mode auto-generates undo logs for Saga-like rollback; TCC mode requires you to write the three methods.
My default is the outbox pattern: in one local transaction I update the order table and insert a row into the outbox table, then a relay process polls outbox and publishes to Kafka. Downstream services consume idempotently. This gets you eventual consistency with no 2PC, no coordinator, and the outbox gives you an audit log for free. I reach for TCC only when the business genuinely cannot tolerate eventual consistency — typically money movement between internal accounts — and I budget 2-3x the dev time. 2PC/XA I avoid in greenfield; saw a payment system back in 2019 where a hung coordinator locked up the whole cluster.
Idempotency keys are non-negotiable — every consumer must dedupe by business id.
Chatty cross-service flows? Usually a service-boundary smell. Merging two microservices is sometimes the right answer.
HireMe AI (即答侠) sequences these patterns by "what the interviewer actually expects in 2026" so you don't over-index on 2PC.
Kafka exactly-once is within the Kafka cluster. The database write and the Kafka publish are still two systems — outbox bridges them atomically via the local DB transaction.
Auto-rollback takes undo logs out of the app's data — the framework locks rows during global transactions, which can hurt throughput under contention.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free