Started with 2PC because it felt safe, but the interviewer kept pushing on the coordinator failure scenario and I fumbled it.
Start by framing the problem: coordinating atomic updates across services with independent failure modes. Then compare 2PC, 3PC, and Saga on consistency, availability, and complexity, walking through message flows and failure scenarios for each. Conclude with practical guidance on delivery guarantees, idempotency, and timeouts, emphasizing trade-offs and real-world applicability.
Pro tip: Google values pragmatic trade-offs over theoretical purity: highlight that 2PC/3PC are rarely used in modern microservices due to blocking and coordinator fragility, while Sagas with idempotent operations and compensating actions are preferred for scalability. Mention that exactly-once delivery is impossible in distributed systems; achieve effectively-once via at-least-once delivery plus idempotent consumers.
Ask about consistency needs (strong vs eventual), latency tolerance, failure models, and whether services are internal or third-party. This scopes the protocol choice.
Describe 2PC phases (prepare/commit) and 3PC (canCommit/preCommit/doCommit), including coordinator and participant roles. Walk through failure cases: participant crash, coordinator crash, network partitions, and how 3PC reduces blocking but adds complexity.
Explain choreography vs orchestration, forward recovery vs backward recovery, and compensating transactions. Walk through a sample flow (e.g., order, payment, inventory) and failure handling when a step fails.
Discuss at-least-once vs exactly-once (impossible), and how to achieve effectively-once with idempotent operations (idempotency keys, dedup tables). Explain timeout strategies, retries with backoff, and dead-letter queues.
Summarize trade-offs: 2PC/3PC for strong consistency but poor availability and scalability; Saga for high availability and scalability but eventual consistency. Recommend based on use case, and mention hybrid approaches or outbox pattern.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.