Transactions
Transactions group multiple operations into an atomic unit to ensure consistency and fault tolerance of state changes.
Classification
- ComplexityMedium
- Impact areaTechnical
- Decision typeArchitectural
- Organizational maturityIntermediate
Technical context
Principles & goals
Use cases & scenarios
Compromises
- Deadlocks and lock contention with poor design
- Faulty compensations can produce inconsistent states
- Excessive transaction duration increases system load
- Limit transaction duration and scope
- Use idempotent operations for retries
- Instrument locks, latencies and rollbacks for monitoring
I/O & resources
- Business requirements for data consistency
- Supporting database or messaging infrastructure
- Monitoring and observability tools
- Atomic state changes or consistent end states
- Transaction and error logs
- Metrics for throughput, latency and errors
Description
Transactions are atomic units that ensure consistency of state changes in databases and distributed systems. They provide ACID properties—Atomicity, Consistency, Isolation, Durability—or alternative approaches (sagas, idempotent operations) for distributed contexts. Implementation requires coordinated error handling and suitable isolation choices.
✔Benefits
- Ensures consistency and integrity of data changes
- Enables predictable error handling (rollback/compensation)
- Improves traceability through explicit boundaries
✖Limitations
- Strong isolation can limit performance and concurrency
- Distributed transactions increase complexity and latency
- Not all systems fully support ACID in distributed scenarios
Trade-offs
Metrics
- Transaction throughput (TPS)
Number of completed transactions per second; measures system capacity.
- Transaction latency
Average time from start to commit/rollback; important for user experience.
- Rollback rate
Share of transactions that are rolled back; indicates errors and conflicts.
Examples & implementations
ACID transaction in a relational DB
A money transfer between accounts as an atomic DB transaction with commit/rollback.
Saga for distributed order
Linked steps (payment, shipping, inventory) are coordinated via local transactions and compensations.
Optimistic concurrency control
Read, modify and conditional write with version checks to avoid locks.
Implementation steps
Analyze consistency requirements and SLAs
Select suitable patterns (ACID, saga, idempotent APIs)
Implement with tests, monitoring and compensation logic
⚠️ Technical debt & bottlenecks
Technical debt
- Legacy systems without transactional guarantees
- Ad-hoc compensations instead of unified strategies
- Insufficient tests for error and retry paths
Known bottlenecks
Misuse examples
- Using 2PC over remote, unstable networks without timeouts
- Excessive lock times due to large transaction batches
- Ignoring isolation effects in parallel updates
Typical traps
- Chasing perfect consistency without considering availability
- Underestimating complexity of distributed error handling
- Lack of observability leads to hard-to-diagnose rollbacks
Required skills
Architectural drivers
Constraints
- • Database or platform capabilities (e.g., 2PC support)
- • Business requirements for latency and throughput
- • Regulatory requirements for traceability