How does High Replication Datastore implement consistent reads
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
High Replication Datastore (HRD), notably used in Google App Engine, is designed to provide strong consistency along with high availability and durability. HRD achieves this through a combination of distributed systems techniques including replication, transaction logs, and entity groups. Here's an in-depth look at how High Replication Datastore implements consistent reads, touching upon its core architecture and mechanisms.
Understanding Entities and Entity Groups
In HRD, data is organized into entities, which are like records in a database, and entity groups, which are collections of entities that can be used to define transactional boundaries. An entity consists of a key and properties. A key uniquely identifies the entity and can define a hierarchy for nested entities within an entity group. Entities within the same group can participate in transactions, whereas entities in different groups cannot.
Multi-Version Concurrency Control (MVCC)
HRD employs Multi-Version Concurrency Control (MVCC) to manage data consistency. In MVCC, the datastore maintains multiple versions of a data item simultaneously. Whenever a read occurs, the datastore returns the most recent consistent version of the data available at the time of the read query execution. This mechanism ensures that users see consistent data as of a certain timestamp, known as snapshot isolation.
Replication Across Data Centers
HRD data is replicated across multiple data centers to ensure high availability and durability. This replication is typically done asynchronously. When an update operation is executed, it is first committed to a primary location and then eventually propagated to secondary locations. This method allows HRD to recover quickly from a data center failure but necessitates careful handling to maintain consistency.
Synchronization and Consistency Models
HRD supports both eventual consistency and strong consistency:
- Eventual Consistency: This is provided for global queries that span multiple entity groups. Changes to a single entity group propagate at different speeds, so queries across multiple groups might not immediately reflect recent writes.
- Strong Consistency: This is provided for all read operations that are ancestor queries, limited to a single entity group. These queries leverage the fact that all entities within a group are colocated, meaning they reside in the same physical location.
How Strong Consistency is Achieved
When a write operation (insert, update, delete) is performed on an entity within a group, HRD ensures that all subsequent read operations see the latest state. It does this by:
- Write Operations: Upon a write, HRD logs the change to a globally distributed transaction log which maintains a record of all changes in chronological order.
- Read Operations: When a read request is made, HRD consults the transaction log to ensure the most recent writes are included in any data it serves.
Synchronization And Commit Protocol
To manage the distributed nature of data, HRD likely utilizes a form of synchronous replication for commit protocols within entity groups to ensure that a transaction is either committed across all replicas or rolled back. This normally involves a two-phase commit system:
- Prepare Phase: A transaction leader, chosen from the replicas, prepares all participating replicas for a transaction.
- Commit Phase: Once all replicas report that they are ready, the leader commits the transaction and acknowledges the completion to the client.
Table: Key Mechanisms in HRD Consistency
| Feature | Description |
| Entities & Groups | Organize data, allow transaction boundaries. |
| MVCC | Manages multiple data versions for isolation. |
| Replication | Ensures data is copied across data centers. |
| Eventual Consistency | Standard for global queries, slow sync. |
| Strong Consistency | Used for single-group ancestor queries. |
| Commit Protocols | Ensures atomic changes across replicas. |
Conclusion
High Replication Datastore's design to provide strong consistency amidst high availability and durability emphasizes efficient replication and sophisticated transaction mechanisms. By leveraging entity groups, MVCC, and robust synchronization protocols, HRD can deliver a highly reliable and consistent data storage solution scalable across geographical regions. This makes it an ideal platform for applications requiring both robust data integrity and high performance.
Related reading
- How does HLC hybrid logical clock solve Linearizability and Serializability in distributed transaction?
- How does immutable data make eventual consistency trivial?
- How does kafka ack batch AsyncProducer
- How does kafka decides the partition if I don't mention any
- How does leaderless replication actually work ? Is there really no single co-ordinator / leader node which maintains the replication?
- How does 'LOAD DATA INFILE' work in statement-based replication?
- How does kafka handle network partitions?
- How does Kafka store offsets for each topic?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.