mvcc/README.md
2025-05-10 13:24:50 -06:00

54 lines
2.5 KiB
Markdown

# MVCC - Multiversion Concurrency Control Demo
A simple Go implementation of Multiversion Concurrency Control (MVCC), a technique used by modern databases to manage concurrent transactions.
## About
This repository contains a toy MVCC implementation in Go that demonstrates how databases maintain multiple versions of data to provide consistent reads without blocking writers.
The code illustrates key MVCC concepts:
- Versioned values with timestamps
- Transaction read timestamps that determine which data version is visible
- Write buffering during transactions
- Conflict detection upon commit
## Blog Post
For a detailed explanation of how this implementation works and the concepts behind MVCC, check out the accompanying blog post:
[MVCC: How modern databases keep their cool](https://blog.canoozie.net/how-modern-databases-keep-their-cool/)
## Usage
```go
// Create a new store
store := NewStore()
// Begin a transaction and write a value
tx1 := store.Begin()
tx1.Write("foo", "bar")
err := tx1.Commit()
// Read the value in another transaction
tx2 := store.Begin()
val, ok := tx2.Read("foo")
```
## Limitations
This is an educational implementation and has several limitations compared to production databases:
- No garbage collection of old versions
- Inefficient storage (full value copies rather than deltas)
- Only supports point lookups (no range queries)
- No indexes
- Implements snapshot isolation, not serializable isolation
## License
Copyright (c) 2025 Jeremy Tregunna
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.