Software

Go JSON Database

A file-backed Go database that supports JSON collections, concurrent access and atomic file replacement.

Role
Solo developer
Status
Public source
Technology
Go
Platform
cli
Team size
1 person
Year
2025

Tools Go

Topics Go · Systems · Database · Concurrency

if err := os.Rename(tempPath, path); err != nil {
    os.Remove(tempPath)
    return fmt.Errorf("failed to rename temp file: %w", err)
}
The final replacement step in the storage engine.

Writing a collection

I implemented a storage path that writes data to a temporary file before replacing the collection file. Mutexes coordinate operations inside a process.

Why store by collection

A file per collection keeps the on-disk format easy to inspect. Reads and writes that touch the whole file do more work as a collection grows, which suits a lightweight project with small datasets.

Development notes

Lightweight JSON-based database in Go with CRUD operations, collections, concurrent access with mutex synchronization, and atomic writes.

Learned Go concurrency patterns, mutex synchronization, and atomic file operations while building a simple database

My responsibilities
  • Designed database architecture in Go
  • Implemented CRUD operations with concurrency safety
  • Built atomic write system with file swaps
  • Created logging and error handling
Design & engineering concepts
  • Collection-based JSON storage with file-per-collection
  • Mutex synchronization for concurrent read/write safety
  • Atomic writes with temporary file swap pattern
  • Basic query operations on JSON documents
Mechanics & implementation
  • CRUD operations with type-safe Go interfaces
  • Concurrent access without data races
  • Logging for debugging and monitoring
  • Simple query DSL for filtering
Lessons learned
  • Concurrency safety requires careful lock management
  • Atomic writes prevent data corruption during crashes
  • JSON databases trade flexibility for query performance
Problem

Learn database-like file storage and concurrency without relying on an external database server or ORM.

Approach

Lightweight JSON-based database in Go.

Engineering details
  • CRUD
  • Collections
  • Concurrent access
  • Mutex synchronization
  • Atomic writes
  • Temporary-file replacement
  • Logging