Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Database Layer

A distributed database system built with TypeScript and PostgreSQL, featuring consistent hashing, vector clocks for versioning, and quorum-based replication.

Architecture

┌─────────────────────────────────────────────────────────┐
│                     Express API                         │
├─────────────────────────────────────────────────────────┤
│  Hash Ring          │  Vector Clock    │  Handler       │
│  (CRC32)            │  (Versioning)    │  (CRUD + Quorum)│
├─────────────────────────────────────────────────────────┤
│     PostgreSQL 1    │  PostgreSQL 2    │  PostgreSQL 3  │
└─────────────────────────────────────────────────────────┘

Features

  • Consistent Hashing - CRC32-based hash ring for deterministic data distribution
  • Vector Clocks - Conflict detection and causal ordering of events
  • Quorum Replication - Write succeeds only when majority of replicas confirm
  • Automatic Failover - Reads try multiple replicas on failure

Quick Start

# Start PostgreSQL instances
docker compose up -d

# Install dependencies
npm install

# Run the server
npm run dev

API Endpoints

Method Endpoint Description
POST /db Create record
GET /db/:id Get record by ID
PUT /db/:id Update record

Example

# Create
curl -X POST http://localhost:8080/db \
  -H "Content-Type: application/json" \
  -d '{"name": "John", "email": "john@example.com"}'

# Read
curl http://localhost:8080/db/{id}

# Update
curl -X PUT http://localhost:8080/db/{id} \
  -H "Content-Type: application/json" \
  -d '{"name": "John Updated"}'

Configuration

[server]
port = 8080

[postgres]
nodes = ["postgres://...@localhost:5432/db1", "..."]

[replication]
factor = 2              # Number of replicas per record
hash_ring_replicas = 50 # Virtual nodes per physical node

Tech Stack

  • Runtime: Node.js + TypeScript
  • Framework: Express.js
  • Database: PostgreSQL
  • Hashing: CRC-32

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages