Key-range locks protect a range of rows implicitly included in a record set being read by a Transact-SQL statement while using the serializable transaction isolation level. The serializable isolation level requires that any query executed during a transaction must obtain the same set of rows every time it is executed during the transaction. A key range lock protects this requirement by preventing other transactions from inserting new rows whose keys would fall in the range of keys read by the serializable transaction.

Key-range locking prevents phantom reads. By protecting the ranges of keys between rows, it also prevents phantom insertions into a set of records accessed by a transaction.

A key-range lock is placed on an index, specifying a beginning and ending key value. This lock blocks any attempt to insert, update, or delete any row with a key value that falls in the range because those operations would first have to acquire a lock on the index. For example, a serializable transaction could issue a SELECT statement that reads all rows whose key values are between AAA and CZZ. A key-range lock on the key values in the range from AAA to CZZ prevents other transactions from inserting rows with key values anywhere in that range, such as ADG, BBD, or CAL.


Xây dựng event store với chỉ duy nhất một bảng mà vẫn đảm bảo giải quyết vấn đề concurrency ok 😡

Phatom row là hiện tượng khi bạn select dữ liệu ra, thì trong lúc đó có row mới được insert vào database. Có nhiều chế độ lock khác nhau, nhưng hầu hết các chế độ lock đó sẽ không lock việc tranh chấp việc insert. Nếu bạn lock cả table thì hiệu năng sẽ rất kém. Key Range Locking cho phép bạn lock một nhóm các row có cùng id. Mà không lock các khoảng key range khác.

Trong việc build event store, thì việc sử dụng lock key range sẽ vô cùng hiệu quả. Vì cá event của một object sẽ cùng một key. Do đó chỉ việc lock nhóm key đó là có thể giải quyết vấn đề concurrency ngon lành.

Reference: fb nghia

57 engineers to serve 1 billion users, amazing!!!. Startup life is always crazy and full of surprises, still so much things to learn!

A Fulfillment Service is a third party warehouse that prepares and ships orders on behalf of the store owner. Fulfillment services charge a fee to package and ship items and update product inventory levels. Some well known fulfillment services with Shopify integrations include: Amazon, Shipwire, and Webgistix

Full source: link