πŸ—οΈ ACID & CAP

GunhoΒ·2025λ…„ 1μ›” 14일
0

Object Oriented Programming (OOP) & Java

λͺ©λ‘ 보기
29/29

πŸ—οΈ Overview

A distributed system is a computing model where multiple computers are connected through a network and work together as a single system. In a distributed system, managing data is crucial, so the choice of database plays a key role.

A database is essential for storing, retrieving, modifying, and managing the system's data. Specifically, distributed systems must consider factors such as data consistency, availability, and partition tolerance, which are commonly referred to as the CAP theorem.

Moreover, databases should ensure data consistency and reliability through the `ACID properties`.

The CAP theorem and ACID properties will be discussed in more detail in the following sections.

🦺 ACID

🦺 ACID refers to a set of core principles that ensures data consistency and reliability. It consists of four key components: Atomicity, Consistency, Isolation, and Durability.

ACID specifically outlines how a database transaction, which is the smallest logical unit in database operations, should be conducted.

To better illustrate the idea of ACID, an example from the finance sector, where strict adherence to these principles appears essential may be considered.


βš›οΈ Atomicity

βš›οΈ Atomicity ensures that internal operations within a single transaction will not be partially reflected in a database, implying there will be either a complete success or a complete failure.

In other words, failing to achieve a single operation out of multiple operations would result in a failing over a whole transaction.

For instance, failing to conduct operation #2 from the financial operations below would result in operation #1 not reflected:

  1. withdraw $2 from an account A
  2. deposit $2 to an account B

🧱 Consistency

🧱 Consistency ensures that when a transaction is successfully completed, the database remains in a consistent state.

Specifically, if a transaction violates rules defined in the database, such as constraints, the transaction must be canceled to maintain consistency.

For instance, a financial transaction exceeding the remaining balance of a account may not be permitted.


🏝️ Isolation

🏝️ Isolation ensures that multiple transactions executed concurrently remain independent of each other where these transactions in the extreme settings could run sequentially at the cost of performances.

No operation outside a transaction can view or interfere intermediate data during the transaction's execution.

For instance, during a money transfer, if the total balance of Account A at $ 10,000, there may be moments when the total does not equal $ 10,000 during the transaction. However, other transactions must always see the total balance as $ 10,000.


πŸ”‹ Durability

πŸ”‹ Durability ensures that once a transaction is successfully completed, its effects are permanently recorded.

Even if a system failure occurs, the results of a successful transaction must always be reflected in the database. Typically, transactions are logged, and only when the log is securely stored is a transaction considered successful. If a failure occurs later, the database can be recovered using these logs.


🦎 CAP

🦎 CAP refers to a theorem where out of Consistency, Availability, and Partition Tolerance at most two properties can be logically attained.

Geeks for Geeks Available at here



πŸ” Consistency

πŸ” Consistency ensures that all nodes (databases) within a network have identical and most up-to-date copies of a replicated data item accessible to various transactions.

Geeks for Geeks Available at here


πŸ™ Availability

πŸ™ Availability refers that every read or write request for a data item will receive a successful response with it potentially being the non-latest data.

Geeks for Geeks Available at here


🎳 Partition Tolerance

🎳 Partition Tolerance means that the system remains operational even under network failures.

Geeks for Geeks Available at here


πŸŽ₯ Scenarios

πŸŽ† CA (Consistency + Availability)

  • e.g. centralised database

    • only way to avoid databases running in different networks.
    • cannot scale over high traffic.

πŸŽ‡ CP (Consistency + Partition Tolerance)

  • e.g. inventory databases

    • for tasks like inventories that require high reliability, consistency can be chosen over a availbility.

πŸŒ… AP (Availability + Partition Tolerance)

  • e.g. social media databases

    • πŸ‘ likes may not have to be as consistent as inventories, hence, availability can be chosen over a consitency.


πŸ“š References

F-Lab (1)
F-Lab (2)
Geeks for Geeks
IBM

profile
Hello

0개의 λŒ“κΈ€