Stateful Databases: A Deep Dive with Cassandra & TiDB

CK CK 3788 
Created at  
190 0 0

What is a Stateful Database?

A stateful database is a type of database system that retains information about past interactions or states and uses this information to process subsequent requests. In essence, it remembers the "state" of the data over time. This means that data written to the database persists and is available for future reads and modifications, maintaining its integrity across operations and sessions.

Simply put, it saves user data permanently so you can seamlessly read and update it whenever you reconnect.

In short, it retains user modifications persistently, allowing you to access and update the exact same data across future sessions.

It means user data is persistently stored and ready to be read or modified upon any future request.

Stateful Databases: A Deep Dive with Cassandra & TiDB

Key characteristics of stateful databases include:

  • Persistence: Data is stored durably and survives system restarts or power failures.
  • Consistency: They often strive to maintain data consistency, ensuring that data is valid according to predefined rules.
  • Transaction Management: They support transactions, which are sequences of operations performed as a single logical unit of work, ensuring atomicity and isolation.
  • Data Integrity: Mechanisms are in place to prevent data corruption and ensure the reliability of stored information.

Most traditional databases, including relational databases, are inherently stateful, as are many NoSQL databases designed for persistent storage.

Yes, probably most of you guys already experienced a stateful database such as MySQL, Postgresql, BigQuery, etc.

 

How is it different from a Relational Database?

While all relational databases are stateful, the question implies a comparison of common stateful database types with the relational model. Here's how relational databases, often serving as a benchmark, compare to other stateful database approaches (which often fall under the "NoSQL" umbrella, like Cassandra, or "NewSQL" like TiDB, aiming for different scaling or consistency models):

Stateful Databases: A Deep Dive with Cassandra & TiDB

Relational Databases (e.g., MySQL, PostgreSQL, Oracle):

  • Data Model: Based on the relational model, organizing data into tables with predefined schemas, rows, and columns. Relationships between tables are defined using foreign keys.
  • Schema: Generally "schema-on-write," meaning the schema must be defined before data can be inserted, and changes typically require schema migrations.
  • Consistency Model: Primarily adhere to ACID properties (Atomicity, Consistency, Isolation, Durability), prioritizing strong consistency.
  • Scalability: Traditionally scale vertically (more powerful hardware), though horizontal scaling (sharding) is possible but often complex to manage.
  • Query Language: Standardized SQL (Structured Query Language).
  • Strengths: Excellent for complex queries, data integrity, transactions, and applications requiring strong consistency.

Other Stateful Databases (often NoSQL or NewSQL, like Cassandra, MongoDB, TiDB):

  • Data Model: Varies widely, including key-value, document, column-family, graph, or distributed SQL. They might offer more flexible ways to store and structure data.
  • Schema: Can be "schema-on-read" (flexible, schema defined when reading) or "schema-on-write" with flexible column definitions (Cassandra), or even full SQL schema (TiDB).
  • Consistency Model: Often prioritize availability and partition tolerance over immediate strong consistency, offering tunable consistency (Cassandra) or strong consistency with distributed ACID transactions (TiDB). They may adhere to BASE properties (Basically Available, Soft state, Eventually consistent).
  • Scalability: Designed for horizontal scalability from the ground up, allowing easy distribution of data and workload across many commodity servers.
  • Query Language: Can vary from specific query languages (e.g., CQL for Cassandra), API calls, or standard SQL (e.g., TiDB's MySQL compatibility).
  • Strengths: High availability, massive scalability (horizontal), ability to handle unstructured or semi-structured data, high throughput for specific access patterns, resilience to failures.

In essence, while both store persistent state, relational databases emphasize rigid structure and strong consistency, whereas other stateful databases often prioritize flexibility, massive scale, and availability, sometimes by relaxing consistency guarantees or adopting a distributed SQL approach.

 

 

Information for Cassandra and TiDB

FeatureApache CassandraTiDB
TypeNoSQL, Wide-Column Store, Distributed databaseNewSQL, Distributed SQL Database
Data ModelColumn-family, key-value with structured columnsRelational (Tables, Rows, Columns), MySQL compatible
ConsistencyTunable (from eventual to strong quorum consistency)Strong (ACID transactions, Serializable Snapshot Isolation by default)
ScalabilityHorizontal (shared-nothing architecture, peer-to-peer)Horizontal (distributed architecture, separates storage/compute)
SchemaSchema-on-write (flexible column definition, no joins)Schema-on-write (standard SQL DDL)
Query LanguageCQL (Cassandra Query Language), similar to SQLMySQL-compatible SQL
Use CasesHigh-volume writes, time-series data, IoT, real-time analytics, personalization, messaging, operational intelligence, fraud detection, social mediaHTAP (Hybrid Transactional/Analytical Processing), large-scale relational workloads, financial services, e-commerce, gaming, SaaS, real-time analytics, critical business applications requiring strong consistency
Key StrengthHigh availability, linear scalability, high write throughput, tunable consistency, always-on, multi-datacenter replicationMySQL compatibility, strong consistency with horizontal scalability, HTAP capabilities, high availability, geo-distributed transactions, resilience to failures
FoundationDerived from Amazon Dynamo and Google BigTableCompatible with MySQL, inspired by Google Spanner and F1

 

 

Example System Architecture using Cassandra

Cassandra's architecture is a distributed, decentralized, and peer-to-peer system designed for high availability and linear scalability.

Stateful Databases: A Deep Dive with Cassandra & TiDB

Explanation:

  • Client Applications: Interact with the Cassandra cluster through application services.
  • Load Balancer / DataStax OpsCenter Driver: Clients (or application services) connect to the Cassandra cluster. While a generic load balancer can be used, Cassandra's client drivers are often intelligent enough to handle load balancing and fault tolerance by themselves, connecting directly to multiple nodes.
  • Cassandra Cluster (Ring Topology):
    • Nodes: Each Cassandra node in the cluster runs identical software and can handle read/write requests.
    • Ring Topology: Nodes are organized into a ring. Data is partitioned and distributed across the nodes.
    • Replication: Data is replicated across multiple nodes (determined by the Replication Factor) to ensure high availability and fault tolerance. In a multi-datacenter setup, data is replicated across different DCs for geo-redundancy and disaster recovery.
    • Gossip Protocol: Nodes communicate using a gossip protocol to discover each other, track state, and detect failures without a central master.

This architecture ensures no single point of failure, allowing the system to continue operating even if multiple nodes or entire data centers become unavailable.

 

 

Example System Architecture using TiDB

TiDB is a NewSQL database designed for large-scale, strongly consistent, and horizontally scalable relational workloads, often used for Hybrid Transactional/Analytical Processing (HTAP). It separates the SQL layer, the scheduling layer, and the distributed key-value storage layer.

Stateful Databases: A Deep Dive with Cassandra & TiDB

Explanation:

  • Client Applications: Connect to TiDB using standard MySQL clients or connectors.
  • Load Balancer: Distributes incoming MySQL-compatible SQL queries across multiple TiDB Server instances.
  • TiDB Servers: These are the SQL layer. They parse SQL, optimize queries, and interact with the PD and TiKV clusters to execute transactions and retrieve/store data. They are stateless and can be scaled independently.
  • PD Cluster (Placement Driver): The "brain" of the TiDB cluster. It stores metadata, performs global timestamp allocation for transactions, and schedules data distribution and load balancing across the TiKV nodes. It typically runs as a small, highly available cluster (e.g., 3-5 nodes) using Raft for consensus.
  • TiKV Cluster (Distributed K-V Storage): The distributed transactional key-value store. It stores all the actual data in sorted key-value pairs. Data is automatically sharded into "regions" and replicated across multiple TiKV nodes using Raft consensus for strong consistency and high availability. It scales horizontally by adding more TiKV nodes.
  • TiFlash Cluster (Optional): An analytical column store engine. It replicates data from TiKV in a columnar format to accelerate analytical queries, enabling HTAP capabilities.

This layered architecture allows for independent scaling of compute (TiDB Servers), storage (TiKV/TiFlash), and scheduling (PD), providing flexibility and high performance for both transactional and analytical workloads.

 

 

Tags Cassandra Cassandra Architecture Database Comparison Database Types MySQL NewSQL NoSQL NoSQL Database Relational Database Stateful Database System Architecture TiDB TiDB Architecture Facebook X
Comments 0
Similar posts
  1. Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures
    157
  2. Enterprise-Scale 100k+ TPS Order Processing System Architecture
    179
  3. Architecting Dynamic Scale-Out and Scale-In with Docker Containers
    134
  4. Architecture Design - Database Partitioning vs. Sharding
    153
  5. How to set AUTO_INCREMENT ID in mySQL ?
    607
  6. Change MySQL port number for security purpose
    816
  7. Using MySQL in Node.js
    481
  8. Rust code example to access MySQL
    1,098
  9. The Ultimate Data Engineering Roadmap
    1,073
  10. Learning about Firestore: Architecture, Pros, Cons, and Real-World Deployments
    168
  11. How do I create a user account in read-only mode at MySQL?
    3,322
  12. Cloud-Native Capital Markets: Architecture, Compliance, and Innovation
    216
  13. Arm Kernel DNNs: Powering Efficient AI at the Edge
    225
  14. The Blueprint of Success: Why System Design and Architecture Matter?
    401
  15. Redis vs Memcached: Why Enterprise Tech Giants Choose Redis
    252
  16. Bridging the Gap: How Machine Learning Integrates with Infrastructure
    277
  17. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    167
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    232
  20. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  21. The Two Clocks of Ad Server Architecture
    71
  1. Difference between CPU and GPU - Why GPU is faster than CPU?
    805
  2. gRPC - Open-source Universal RPC Framework developed by Google
    768
  3. Exploring the Depths of Data Transfer: sendfile vs. kTLS
    1,320
  4. How Netflix Ensures Smooth Streaming with Open Connect CDN
    2,130
  5. Public DNS (Domain Name Service) based on IPv4, IPv6 widely used
    1,244
  6. All Engineering Software Development How can you prioritize software design trade-offs when developing a new product?
    1,340
  7. MR(Mixed Reality) Game Programming based on Unity 3D
    1,360
  8. Temporal Programming Model - Robust, Long-Running, Fault-Tolerant Applications as WorkFlows
    358
  9. Cadence Programming Model - A Distributed, Fault-Tolerant, Stateful Workflow Orchestration Framework
    294
  10. Multi-AZ Kafka Architecture
    149
  11. Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”
    271
  12. Hybrid Methods for Recommendation Service
    219
  13. Model-Based CF: Matrix Factorization for Recommendation Service
    183
  14. Memory-Based Collaborative Filtering for Recommendation Service
    195
  15. Content-Based Filtering for Recommendation Service (aka User-based Model)
    192
  16. Why Kubernetes? Core Features and Microservice Orchestration Strategies
    575
  17. Quiz : Twice counter
    700
  18. Kubernetes, aka K8s, is an open-source container orchestration platform
    540
  19. Architecting for Resilience: AWS High Availability Components Including API Gateway
    139
  20. Is AWS API Gateway Disaster-Proof? DR, Benefits, and Multi-AZ Architecture Explained
    143
  21. FNC(Photo/Video File Name Changer) v1.1 Release - Date Time Bug Fix & Retry Function Added
    705
  22. Smart TV Cycling Apps – TV for Fitness
    809
  23. The public could reduce server cost, and enhance performance for global service distribution
    10,743
  24. Cloud gaming coming to Samsung Smart TVs
    558
  25. Kids App – Kids Learn While Parents Control on Samsung Smart TV
    763
  26. Fitness Hub presents your personal trainer, Fitness VOD on Samsung Smart TV
    521
  27. Word counting source program based on MapReduce framework
    692
  28. The leaders who created Smart TV
    813
  29. FNC(Photo/Video File Name Changer) v1.02 release - The file created date time information is available for those cameras providing incorrect EXIF data
    977
  30. Samsung Apps hits 5 million Smart TV app downloads
    650
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  3. How do I create animated background for Google Meet?
    21,044
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    252
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    158
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. Frequency Cap Architecture Overview
    515
  11. Collecting Proof-of-Play from 100,000 Screens
    146
  12. What is RedisVL?
    109
  13. TPU & GPU Cluster Management Tools
    245
  14. The Concept of Scaffolding in AI Agents
    234
  15. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  16. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  17. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  18. Machine Learning: Training vs. Ranking
    222
  19. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  20. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  21. Designing a Data Curation System Around a Vector Database
    221
  22. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    257
  23. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  24. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  25. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  26. Understanding Data Lineage
    263
  27. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    245
  28. Java Variant Type
    202
  29. When Do You Need Real-Time Model Registry Versioning Powered by Autonomous Agents?
    230
  30. From SDI to MXL: Inside the Cloud-Native Infrastructure Powering Next-Gen Live Broadcast
    570