Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems
Rate it:
Open Preview
33%
Flag icon
index simply point to all versions of an object and require an index query to filter out any
33%
Flag icon
For example, PostgreSQL has optimizations for avoiding index updates if different versions of the same object can fit on the same page
Chena Lee
??
33%
Flag icon
they use an append-only/copy-on-write variant that does not overwrite pages of the tree when they are updated, but instead creates a new copy of each modified page.
33%
Flag icon
append-only B-trees, every write transaction (or batch of transactions) creates a new B-tree root, and a particular root is a consistent snapshot of the database at the point in time when it was created.
33%
Flag icon
However, this approach also requires a background process for compaction and garbage collection.
33%
Flag icon
Snapshot isolation
33%
Flag icon
In Oracle it is called serializable, and in PostgreSQL and MySQL it is called repeatable read
33%
Flag icon
Instead, it defines repeatable read, which looks superficially similar to snapshot isolation.
33%
Flag icon
PostgreSQL and MySQL call their snapshot isolation level repeatable read because it meets the requirements of the standard,
33%
Flag icon
the SQL standard’s definition of isolation levels is flawed — it is ambiguous, imprecise, and not as implementation-independent as a standard should be
33%
Flag icon
ostensibly
33%
Flag icon
nobody really knows what repeatable read means.
33%
Flag icon
Preventing Lost Updates
33%
Flag icon
(a read-modify-write cycle).
33%
Flag icon
Atomic write operations
33%
Flag icon
atomic update operations, which remove the need to implement read-modify-write cycles in application code.
33%
Flag icon
UPDATE counters SET value = value + 1 WHERE key = 'foo';
33%
Flag icon
MongoDB provide atomic operations for making local modifications to a part of a JSON document,
33%
Flag icon
Redis provides atomic operations for modifying data structures such as priority queues.
33%
Flag icon
Not all writes can easily be expressed in terms of atomic operations — for example, updates to a wik...
This highlight has been truncated due to consecutive passage length restrictions.
33%
Flag icon
exclusive lock on the object when it is read so that no other transaction can read it until the update has been applied.
33%
Flag icon
cursor stability
33%
Flag icon
simply force all atomic operations to be executed on a single thread.
33%
Flag icon
object-relational mapping frameworks make it easy to accidentally write code that performs unsafe read-modify-write cycles instead of using atomic operations provided by the database
33%
Flag icon
for the application to explicitly lock objects that are going to be updated.
33%
Flag icon
FOR UPDATE clause indicates that the database should take a lock on all rows returned by this query.
34%
Flag icon
An alternative is to allow them to execute in parallel and, if the transaction manager detects a lost update, abort the transaction and force it to retry its read-modify-write cycle.
34%
Flag icon
this approach is that databases can perform this check efficiently in conjunction with snapshot isolation.
34%
Flag icon
Some authors [28, 30] argue that a
34%
Flag icon
database must prevent lost updates in order to qualify as providing snapshot isolation, so MySQL does not provide snapshot isolation under this definition.
Chena Lee
?
34%
Flag icon
databases that don’t provide transactions, you sometimes find an atomic compare-and-set operation
34%
Flag icon
this operation is to avoid lost updates by allowing an update to happen only if the value has not changed since you last read it.
34%
Flag icon
However, if the database allows the WHERE clause to read from an old snapshot, this statement may not prevent lost updates,
34%
Flag icon
Check whether your database’s compare-and-set operation is safe before relying on it.
34%
Flag icon
Conflict resolution and replication
34%
Flag icon
Locks and compare-and-set operations assume that there is a single up-to-date copy of the data.
34%
Flag icon
databases with multi-leader or leaderless replication usually allow several writes to happen concurrently and replicate them asynchronously,
34%
Flag icon
techniques based on locks or compare-and-set do not appl...
This highlight has been truncated due to consecutive passage length restrictions.
34%
Flag icon
resolve and merge these versions after the fact.
34%
Flag icon
Atomic operations
34%
Flag icon
For example, incrementing a counter or adding an element to a set are commutative operations.
34%
Flag icon
Unfortunately, LWW is the default in many replicated databases.
34%
Flag icon
Write Skew and Phantoms
34%
Flag icon
Your requirement of having at least one doctor on call has been violated.
34%
Flag icon
This anomaly is called write skew
Chena Lee
This is like vinyaas like application?
34%
Flag icon
write skew as a generalization of the lost update problem. Write skew can occur if two transactions read the same objects, and then update some of those objects (different transactions may update different objects). In the special case where different transactions update the same object, you get a dirty write or lost update anomaly
34%
Flag icon
Automatically preventing write skew requires true serializable isolation
34%
Flag icon
Some databases allow you to configure constraints, which are then enforced by the database (e.g., uniqueness, foreign key constraints, or restrictions on a particular value).
34%
Flag icon
you would need a constraint that involves multiple objects. Most databases do not have built-in support for such constraints, but you may be able to implement them with triggers or materialized views, depending on the database
34%
Flag icon
the second-best option in this case is probably to explicitly lock the rows that the transaction depends on.
1 9 28