트랜잭션 ACID에서 C가 이상해요

jYur·2023년 5월 15일
0

"However, in practice, one database’s implementation of ACID does not equal another’s implementation. For example, as we shall see, there is a lot of ambiguity around the meaning of isolation. The high-level idea is sound, but the devil is in the details. Today, when a system claims to be “ACID compliant,” it’s unclear what guarantees you can actually expect. ACID has unfortunately become mostly a marketing term."
Designing Data-Intensive Applications, Martin Kleppmann

REST랑 느낌이 비슷한데?

ACID란 ?
제대로 된 "트랜잭션"이라면 네 가지(Atomicity, Consistency, Isolation, Durability)는 충족해야 한다라는 의미로 만든 건데, 예전부터 "Consistency(일관성)"는 뭔가 와닿지 않았다.

쉽게 찾아볼 수 있는 설명들이 참 불친절한 것 같다. 읽어도 제대로 이해되지 않는다.

위키피디아

일관성(Consistency)은 트랜잭션이 실행을 성공적으로 완료하면 언제나 일관성 있는 데이터베이스 상태로 유지하는 것을 의미한다. 무결성 제약이 모든 계좌는 잔고가 있어야 한다면 이를 위반하는 트랜잭션은 중단된다.

일관성은 일관성을 유지하는 것이다?

ACID를 만든 사람의 설명

Consistency. A transaction reaching its normal end (EOT, end of transaction), thereby committing its results, preserves the consistency of the database. In other words, each successful transaction by definition commits only legal results.
― Theo Haerder, Andreas Reuter(1983). Principles of Transaction-Oriented Database Recovery

대충, 제약 사항에 위배되지 않는 결과만 커밋해야 된다는 소리

마지막으로 요즘 핫한 AI님들의 정의도 한번 보자.
GPT-4

일관성(Consistency): 트랜잭션 전후로 데이터베이스의 일관성이 유지되어야 합니다. 즉, 트랜잭션이 실행되기 전에 데이터베이스가 일관된 상태였다면 실행 후에도 동일한 일관된 상태를 가져야 합니다.

🤪

Bard

일관성: 트랜잭션이 완료되면 데이터베이스가 일관된 상태여야 한다는 것을 의미합니다. 즉, 모든 데이터베이스 규칙과 제약을 준수해야 합니다. 예를 들어, 데이터베이스에 "계좌 잔액은 0보다 커야 합니다"라는 규칙이 있는 경우 트랜잭션은 계좌 잔액을 0 이하로 만들 수 없습니다.

데이터베이스의 계좌 테이블의 잔고 컬럼에 0 미만 값을 넣으려고 하면 트랜잭션이 중단된다는 거야?


😎 이제 진짜 정체를 밝혀 보자

Atomicity, Isolation, and Durability are properties of the database, whereas consistency (in the ACID sense) is a property of the application. The application may rely on the database's atomicity and isolation properties in order to achieve consistency, but it's not up to the database alone. Thus, the letter C doesn't really belong in ACID.
― Martin Kleppmann(2017), Designing Data-Intensive Applications

"Consistency"는 나머지 세 가지와 다르게, database의 속성이 아니라 application의 속성이란다.
(AID는 마음에 안 들었는지, ACID라는 약어를 만들기 위해 C를 끼워넣은 거라는 말도 있다)

Prisma 블로그 글에서도 같은 얘기를 한다. (이 글을 쓰게 된 계기)

consistency could actually be considered an application-level responsibility rather than a database property
― Nikolas Burk, Søren Bramer Schmidt(2020), How Prisma Supports Database Transactions

"consistency"는 사실 DB 속성이라기보다 애플리케이션 레벨의 책임으로 볼 수 있단다.

결국, 애플리케이션 코드에서 트랜잭션 처리 중 비지니스 규칙이나 제약 사항에 위배되는 경우 예외를 던지던 것을 말하는 것 같다.

0개의 댓글