Database / Google Spanner Database Interview questions
What is the difference between read-write and read-only transactions in Spanner?
| Read-write transaction | Read-only transaction |
| Uses locking and two-phase commit to safely mix reads and writes. | Never takes locks; only reads data. |
| Always reads the latest committed data (strong reads). | Can read at a specific timestamp, including a slightly stale one. |
| Higher latency due to commit coordination across replicas. | Lower latency, and can be served from the nearest read replica. |
Read-write transactions are the only way to write data and are used whenever a read result influences a subsequent write. Read-only transactions are cheaper because they skip locking entirely; using exact staleness or bounded staleness with a read-only transaction lets an application trade a small amount of freshness for significantly lower latency, which matters for read-heavy, latency-sensitive workloads like dashboards or product catalogs.
More Related questions...