DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Split-Brain in Distributed Systems
  • How to Integrate a Distributed Database With Event Streaming
  • Implement a Distributed Database to Your Java Application

Trending

  • Enforcing Architecture With ArchUnit in Java
  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  • MCP Servers: The Technical Debt That Is Coming
  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  1. DZone
  2. Data Engineering
  3. Databases
  4. Session Management in Distributed Databases

Session Management in Distributed Databases

Session management in distributed databases is fundamental to ensuring data consistency. In this article, learn about session consistency and session tokens.

By 
Bhala Ranganathan user avatar
Bhala Ranganathan
DZone Core CORE ·
Mar. 05, 24 · Analysis
Likes (1)
Comment
Save
Tweet
Share
2.9K Views

Join the DZone community and get the full member experience.

Join For Free

Distributed databases partition the data across several nodes, spreading across regions depending on the database configuration. Such partitioning is fundamental to achieving scalability. All such cloud-native databases have some sort of a session management layer. A session, in plain terms, is the span of communication between a database client and server. It can span multiple transactions. I.e., in a given session, a client can do many writes and reads. The session management layer is usually responsible for guaranteeing “read your own writes”. I.e., data written by a user must be available for reading in the same session.

Session Consistency

In the distributed database world, with many regions serving the database, reads can happen from anywhere. There is fundamentally a need to distinguish between “Not Found” and “Not Available” scenarios. I.e. in the former case data does not exist while in the latter case, data is yet to be seen by the region. This is important to provide a “read your own write” guarantee. For example, let’s look at the time steps that happen in the below picture.

  • T1: User A using session A is writing the value of x as 1.
  • T2: User A using the same session A is attempting to read the value of x. The returned output will be 1.
  • T3: User B in session B is reading a value of x but will get “Not Found” since the West US region has not yet seen the data.
  • T4: The value of x is replicated from the East US to the West US region.
  • T5: User C in session C when reading the value of x will now see the value as 1.

East vs. West

Now let’s look at the scenario of the outage, as shown in the picture below. 

  • T1: User A using session A is writing the value of x as 1.
  • T2: Outage happens at East US, and User A is not able to connect to East US.
  • T3: The user using the same session A is attempting to read the value of x. Now, the call may get routed to another available region (West US). Note that replication has not been completed. So the user must not be returned “Not Found.” Otherwise, it would break the “read your own write” guarantee.
    outage

Session Token

In the outage example shown above, one might wonder what the West US region should do in this case. There are two sub-problems:

  • How does a region know it can’t return “Not Found”?
  • What action should it alternatively take if it can’t return “Not Found”? 

This is where session tokens are useful. A session token contains information about a region’s progress. In the above example, Session A has seen more progress than West US. In that case, by inspecting the session token West US region can determine that it is lagging behind and can’t serve this request. Instead, it can reroute the request back to East US. In such a case, a session token can look like “[East US: 1, West US:0],” indicating East US has progressed by one operation and West US has not seen any operations. To generalize, a typical breakdown of session tokens will look like this:

Session token = “{region1: progress1, region2:progress2 …}”

Conclusion

In conclusion, session management in distributed databases is fundamental to ensuring data consistency. Different databases could implement a session token differently than what is described here but fundamentally they are designed to provide “read your own write” guarantees. In addition, a session token can encode additional information as well, for example, if it has partition information, then the request can be routed to the correct partition within the same region.

Further Reading

  1. MongoDB Manual
  2. Microsoft Azure Cosmos
  3. Amazon Dynamo DB
Database Distributed database

Opinions expressed by DZone contributors are their own.

Related

  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Split-Brain in Distributed Systems
  • How to Integrate a Distributed Database With Event Streaming
  • Implement a Distributed Database to Your Java Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!