Prev Next

Database / Google Spanner Database Interview questions

What happens internally when Spanner commits a distributed transaction?

For a transaction touching multiple splits, Spanner's client picks one participant Paxos group as the transaction coordinator and runs a two-phase commit protocol across all groups involved.

sequenceDiagram participant Coord as Coordinator Group participant P1 as Participant Group 1 participant P2 as Participant Group 2 Coord->>P1: Prepare Coord->>P2: Prepare P1-->>Coord: Prepared (locks held) P2-->>Coord: Prepared (locks held) Coord->>Coord: Choose commit timestamp (TrueTime) Coord->>Coord: Commit wait Coord->>P1: Commit at timestamp Coord->>P2: Commit at timestamp P1-->>Coord: Ack P2-->>Coord: Ack Coord-->>Coord: Return success to client

In the prepare phase, every participant group replicates its portion of the write via its own Paxos majority and reports back "prepared," meaning it has durably logged the intent but not yet made it visible. The coordinator then picks a single commit timestamp, using TrueTime, that is later than all participants' prepare timestamps, and performs commit wait to ensure that timestamp has definitely passed. In the commit phase, it tells every participant to apply the write at that timestamp and release locks. If any participant fails to prepare, the coordinator aborts the whole transaction and every participant rolls back, preserving atomicity across splits that may live on entirely different machines.

What does a participant group report after successfully logging its part of the write?
What happens if one participant fails to prepare?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Robinhood Logo

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is Google Cloud Spanner? What are the main features of Google Spanner? What is the purpose of TrueTime in Spanner? Define interleaved tables in Google Spanner? What is a Spanner instance? What are processing units in Google Spanner? Describe primary keys in Google Spanner schema design? What are the supported database dialects in Spanner? List the data types supported by Google Spanner? How do you create a database in Google Spanner? What is a secondary index in Spanner? Explain the purpose of splits in Spanner? What are mutations in Google Spanner? How do you apply schema changes in Spanner? What is the Spanner emulator? Why does Spanner use TrueTime for consistency? How does Spanner achieve external consistency? What is the difference between read-write and read-only transactions in Spanner? When should you use interleaved tables versus foreign keys? What happens when a hotspot occurs in Spanner? How is data partitioned across nodes in Spanner? Why should you avoid monotonically increasing primary keys? What is the difference between Spanner and Cloud SQL? How does Spanner handle schema changes without downtime? When would you choose bounded staleness over strong reads? How can you optimize query performance in Spanner? What is the difference between Data Boost and standard reads? Why do we use commit timestamps in Spanner tables? How does Spanner's query optimizer choose an execution plan? What is the difference between batch DML and partitioned DML? When should you use change streams in Spanner? How is fine-grained access control implemented in Spanner? Why doesn't Spanner support auto-incrementing primary keys? What is the difference between GoogleSQL and PostgreSQL dialects in Spanner? How do you troubleshoot high latency in Spanner queries? Explain the internal working of Paxos in Spanner replication? Explain the execution flow of a read-write transaction in Spanner? Explain the lifecycle of a split in Spanner? How does Spanner guarantee external consistency across regions? What happens internally when Spanner commits a distributed transaction? How can you optimize a multi-region Spanner configuration for latency? Which is better and why: multi-region or regional Spanner configuration for a global app? How does directed reads improve read latency in multi-region Spanner? Why is clock skew uncertainty critical to Spanner's TrueTime API? How do you troubleshoot transaction aborts in Spanner? Explain the internal working of the Spanner query execution engine? What happens when a leader region becomes unavailable in Spanner? How does Spanner implement point-in-time recovery internally? Explain the execution flow of a partitioned DML statement in Spanner? How can you optimize schema design to avoid hotspotting at scale?
Show more question and Answers...

Integration

Comments & Discussions