<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Van Dang — Writing</title><description>Notes on data systems, platform engineering, and the tools in between.</description><link>https://vandang.info</link><language>en</language><item><title>Concurrency Control</title><link>https://vandang.info/blog/concurrency-control</link><guid isPermaLink="true">https://vandang.info/blog/concurrency-control</guid><description>Databases have long tried to hide concurrency issues from application developers by providing Transaction Isolation. In theory, isolation should make your life</description><pubDate>Sun, 19 Jul 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Databases have long tried to hide concurrency issues from application developers by providing &lt;strong&gt;Transaction Isolation&lt;/strong&gt;. In theory, isolation should make your life easier by letting you pretend that no concurrency is happening.&lt;/p&gt;
&lt;h1 id=&quot;read-uncommitted&quot;&gt;Read Uncommitted&lt;/h1&gt;
&lt;p&gt;This doesn’t provide any isolation (if yes, it will only prevent &lt;a href=&quot;https://vandang.info/blog/concurrency-control#705fec&quot;&gt;Dirty Write&lt;/a&gt;).&lt;/p&gt;
&lt;h1 id=&quot;weak-isolation-levels&quot;&gt;Weak Isolation Levels&lt;/h1&gt;
&lt;h2 id=&quot;read-committed&quot;&gt;Read Committed&lt;/h2&gt;
&lt;p&gt;This prevents:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span id=&quot;705fec&quot; data-block-anchor=&quot;&quot;&gt;&lt;/span&gt;Dirty writes:
&lt;ul&gt;
&lt;li&gt;Definition: One client overwrites data that another client has written, but not yet committed. Almost all transaction implementations prevent dirty writes.&lt;/li&gt;
&lt;li&gt;Implementation: This can be implemented using row level lock.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Dirty reads:
&lt;ul&gt;
&lt;li&gt;Definition: One client reads another client’s writes before they have been committed. The read committed isolation level and stronger levels prevent dirty reads.&lt;/li&gt;
&lt;li&gt;Implementation: This can also leverage the previously discussed lock. However, a long running write will cause other read-only queries to wait. A better approach would be to remember both old-committed value and newly-written-but-not-yet-committed value that holds the lock.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;snapshot-isolation---repeatable-reads&quot;&gt;&lt;a href=&quot;https://vandang.info/blog/snapshot-isolation&quot;&gt;Snapshot Isolation&lt;/a&gt; - Repeatable Reads&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Reads never block Writes and Vice Versa.&lt;/strong&gt;
Note: Repeatable Read is a term from SQL Standard - which is old (System R’s 1975 definition of isolation levels, the term “Snapshot isolation” hasn’t been invented yet), ambiguous, imprecise, and not as implementation-independent as a standard should be. Therefore there is confusion in “Repeatable Read” definition, and “Snapshot Isolation” implementations vary significantly.&lt;/p&gt;
&lt;p&gt;These prevent:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read skew (non-repeatable reads):
&lt;ul&gt;
&lt;li&gt;Definition: A client sees different parts of the database at different points in time. This issue is most commonly prevented with snapshot isolation, which allows a transaction to read from a consistent snapshot at one point in time.&lt;/li&gt;
&lt;li&gt;Implementation: It is usually implemented with multi-version concurrency control (MVCC).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Lost updates:
&lt;ul&gt;
&lt;li&gt;Definition: Two clients concurrently perform a read-modify-write cycle. One overwrites the other’s write without incorporating its changes, so data is lost.&lt;/li&gt;
&lt;li&gt;Implementation: some databases prevent this anomaly automatically (detects and aborts the transaction), some leverage atomic compare-and-set operation, while others require a manual lock (SELECT FOR UPDATE).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;strong-isolation-level---serializability&quot;&gt;Strong Isolation Level - Serializability&lt;/h1&gt;
&lt;p&gt;This prevents:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span id=&quot;57d209&quot; data-block-anchor=&quot;&quot;&gt;&lt;/span&gt;Write skew:
&lt;ul&gt;
&lt;li&gt;Definition: A transaction reads something, makes a decision based on the value it saw, and writes the decision to the database. However, by the time the write is made, the premise of the decision is no longer true. Only serializable isolation prevents this anomaly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Phantom reads:
&lt;ul&gt;
&lt;li&gt;Definition: A transaction reads objects that match some search condition. Another client makes a write that affects the results of that search. Snapshot isolation prevents straightforward phantom reads, but phantoms in the context of write skew require special treatment, such as index-range locks.
There are 3 implementations (of 2 groups):&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Pessimistic: Low performance&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Actual Serial Execution: Single Threaded, Serial order execution. Tips are:
&lt;ul&gt;
&lt;li&gt;Stored Procedure.&lt;/li&gt;
&lt;li&gt;Partitioning.&lt;/li&gt;
&lt;li&gt;Small and Fast transaction.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://vandang.info/blog/two-phases-locking-2pl&quot;&gt;Two Phases Locking - 2PL&lt;/a&gt;: &lt;strong&gt;Reads and Writes block each other&lt;/strong&gt;. Widely used locks:
&lt;ul&gt;
&lt;li&gt;Predicate Lock.&lt;/li&gt;
&lt;li&gt;Index Range Lock.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span id=&quot;665d36&quot; data-block-anchor=&quot;&quot;&gt;&lt;/span&gt;&lt;strong&gt;Optimistic - Serializable Snapshot Isolation (SSI): An integration between &lt;a href=&quot;https://vandang.info/blog/snapshot-isolation&quot;&gt;Snapshot Isolation&lt;/a&gt; and &lt;a href=&quot;https://vandang.info/blog/two-phases-locking-2pl&quot;&gt;Two Phases Locking - 2PL&lt;/a&gt; - New and is getting more widely adopted&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;All reads within a transaction are made from a consistent snapshot of a Database.&lt;/li&gt;
&lt;li&gt;Add algorithm to detect serialization conflicts among writes and which transactions to abort aka &lt;a href=&quot;https://vandang.info/blog/concurrency-control#57d209&quot;&gt;Decisions based on outdated premise&lt;/a&gt;.
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Detecting stale MVCC reads&lt;/strong&gt;: the database needs to track when a transaction ignores another transaction’s writes due to MVCC visibility rules. When the transaction wants to commit, the database checks whether any of the ignored writes have now been committed. If so, the transaction must be aborted.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Detecting writes that affect prior reads&lt;/strong&gt;: use a similar locking technique from &lt;a href=&quot;https://vandang.info/blog/two-phases-locking-2pl&quot;&gt;2PL&lt;/a&gt; like Predicate Lock or Index Range Lock, except that SSI locks don’t block other transactions. When a transaction writes to the database, it must look in the indexes for any other transactions that have recently read the affected data. This process is similar to acquiring a write lock on the affected key range, but rather than blocking until the readers have committed, the lock acts as a tripwire: it simply notifies the transactions that the data they read may no longer be up to date.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;note&quot;&gt;Note&lt;/h1&gt;
&lt;p&gt;Due to the nature of detecting conflict and aborting the transaction, Clients under &lt;a href=&quot;https://vandang.info/blog/snapshot-isolation&quot;&gt;Snapshot Isolation&lt;/a&gt; and &lt;a href=&quot;https://vandang.info/blog/concurrency-control#665d36&quot;&gt;SSI&lt;/a&gt; schemes need to handle Conflict when being aborted.&lt;/p&gt;</content:encoded></item><item><title>Snapshot Isolation</title><link>https://vandang.info/blog/snapshot-isolation</link><guid isPermaLink="true">https://vandang.info/blog/snapshot-isolation</guid><description>A transaction executing under Snapshot Isolation appears to operate on a personal snapshot of the database, taken at the start of the transaction. When the</description><pubDate>Sun, 19 Jul 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A transaction executing under &lt;a href=&quot;https://en.wikipedia.org/wiki/Snapshot_isolation&quot;&gt;Snapshot Isolation&lt;/a&gt; appears to operate on a personal &lt;em&gt;snapshot&lt;/em&gt; of the database, taken at the start of the transaction. When the transaction concludes, it will successfully commit only if the values updated by the transaction have not been changed externally since the snapshot was taken. Such a &lt;a href=&quot;https://en.wikipedia.org/wiki/Write%E2%80%93write_conflict&quot; title=&quot;Write–write conflict&quot;&gt;write–write conflict&lt;/a&gt; will cause the transaction to abort.&lt;/p&gt;</content:encoded></item><item><title>Two Phases Locking - 2PL</title><link>https://vandang.info/blog/two-phases-locking-2pl</link><guid isPermaLink="true">https://vandang.info/blog/two-phases-locking-2pl</guid><description>Two phases locking (2PL) the transactions handles its locking in 2 phases: The expanding phase: No lock can be released The shrinking phase: No lock can be</description><pubDate>Sun, 19 Jul 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://en.m.wikipedia.org/wiki/Two-phase_locking&quot;&gt;Two phases locking (2PL)&lt;/a&gt; the transactions handles its locking in 2 phases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The expanding phase: No lock can be released&lt;/li&gt;
&lt;li&gt;The shrinking phase: No lock can be acquired
Locking rules are:&lt;/li&gt;
&lt;li&gt;Read operations will be granted Shared Locks (meaning reads operations can be executed concurrently on the same item)&lt;/li&gt;
&lt;li&gt;Write operations will be grant Exclusive Locks (meaning they are not compatible with any other operations regardless of their types)
As this protocol can introduce Deadlock, it was extended to a variant called Conservative 2PL (C2PL), where transactions obtain all the locked required before actually beginning -&gt; they won’t have to wait for other locks. However, due to its greediness, it often causes overhead in light-lock contention.
Another variant, Strong strict two-phase locking (SS2PLP) put another constraint in which locks (regardless of type) are released only after transactions end. This implicitly renders the Protocol no longer “2 phases” by “removing phase 2”. This is the one being widely adopted due to its Serializability and Cascadeless Recoverability).&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title>iVim - Vim for iPad</title><link>https://vandang.info/blog/ivim-vim-for-ipad</link><guid isPermaLink="true">https://vandang.info/blog/ivim-vim-for-ipad</guid><description>iVim is vim for iPad and is actually really good, as it (and its plugins, most of them) has already been compiled when installing (even plugins that are</description><pubDate>Sat, 20 Jan 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://apps.apple.com/us/app/ivim/id1266544660&quot;&gt;iVim&lt;/a&gt; is vim for iPad and is actually really good, as it (and its plugins, most of them) has already been compiled when installing (even plugins that are install in lua - lua nature). Therefore, most extensions work seamlessly on iPad.
There are still many quirks when using this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Some bug related to navigations because of iPad security (including syncing, symlinking, …)&lt;/li&gt;
&lt;li&gt;Some extensions don’t work.&lt;/li&gt;
&lt;li&gt;Lua and Python’s features limitation leading to Plugins not working properly.&lt;/li&gt;
&lt;li&gt;Keyboard limitation on iPad (shameful 🙂).&lt;/li&gt;
&lt;li&gt;Had to pay 140k VND for a built-in Plugin Manager as I am too tired manually installing them.&lt;/li&gt;
&lt;li&gt;Couldn’t sync setting using iClouds.
There are many OS-level interaction built-in Commands to use and interact with files from another place (e.g iCloud Drive) and many things more.
The &lt;a href=&quot;https://www.reddit.com/r/vim/comments/9ki5g8/ivim_ios_howtos/&quot;&gt;HowTo&lt;/a&gt; here helps a lot in setting this up.
Some (not to say many) settings depend on iPadOS, therefore setting it in &lt;code&gt;.vimrc&lt;/code&gt; just doesn’t work.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item></channel></rss>