Datastore
High Replication
Consistent Reads
Data Implementation
Database Technology

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.

Practice system design

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:

  1. 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.
  2. 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:

  1. Prepare Phase: A transaction leader, chosen from the replicas, prepares all participating replicas for a transaction.
  2. 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

FeatureDescription
Entities & GroupsOrganize data, allow transaction boundaries.
MVCCManages multiple data versions for isolation.
ReplicationEnsures data is copied across data centers.
Eventual ConsistencyStandard for global queries, slow sync.
Strong ConsistencyUsed for single-group ancestor queries.
Commit ProtocolsEnsures 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.