Introducing Dragonfly Cloud! Learn More

Question: What are ACID vs BASE database examples?

Answer

ACID and BASE are two sets of principles that guide the design and operation of databases, ensuring data integrity and availability. While ACID focuses on strict consistency, BASE prioritizes system availability and partition tolerance.

ACID Principles:

  1. Atomicity: Transactions are all-or-nothing, meaning either all operations succeed or none.
  2. Consistency: Any transaction brings the database from one valid state to another.
  3. Isolation: Transactions are processed independently, without interference.
  4. Durability: Once a transaction is committed, it remains so even in the event of errors or failures.

ACID Database Example: PostgreSQL

PostgreSQL is a popular open-source relational database that adheres to ACID principles. It provides robust transaction management, ensuring data integrity and consistency.

BEGIN; UPDATE accounts SET balance = balance - 100 WHERE account_id = 1; UPDATE accounts SET balance = balance + 100 WHERE account_id = 2; COMMIT;

In this example, the transaction either completes fully, transferring funds between accounts atomically and maintaining consistency, or it fails without altering any account balances.

BASE Principles:

  1. Basically Available: Guarantees the availability of the data without promising complete consistency.
  2. Soft-state: The state of the system may change over time, even without input due to eventual consistency.
  3. Eventually Consistent: The system will become consistent over time but doesn't guarantee immediate consistency.

BASE Database Example: Cassandra

Apache Cassandra is an open-source NoSQL database designed for handling large amounts of data across many commodity servers, providing high availability with no single point of failure.

INSERT INTO user_balances (user_id, balance) VALUES (1, 200); INSERT INTO user_balances (user_id, balance) VALUES (2, 150);

These operations in Cassandra demonstrate basically available transactions. Updates might not be visible immediately to all nodes (soft state), but eventually, all nodes will reflect the correct balances (eventual consistency).

Conclusion:

Choosing between ACID and BASE models depends on your application's requirements. For applications requiring strict data integrity and consistency, an ACID-compliant database like PostgreSQL is suitable. For applications needing to scale massively and can tolerate eventual consistency for the benefit of availability, a BASE-compliant database like Cassandra might be more appropriate.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.