Skip to content

FLIN : A blazing-fast, distributed data platform combining Key-Value Store, Message Queue, Stream Processing, and Document Database in a single unified system.

Notifications You must be signed in to change notification settings

skshohagmiah/flin

Repository files navigation

πŸš€ Flin - Distributed Messaging and Database System

A blazing-fast, distributed system combining Key-Value Store, Message Queue, Stream Processing, and Wide-Column Database in a single unified platform.

⚑ Performance Highlights

Component Throughput Latency Notes
KV Store 319K reads/sec 3.1ΞΌs 3x faster than Redis
KV Store 151K writes/sec 6.6ΞΌs Disk-backed durability
Message Queue 104K push/sec 9.6ΞΌs Unified port with KV
Message Queue 100K pop/sec 10ΞΌs BadgerDB persistence
Stream High throughput Low latency Kafka-like pub/sub
Database 76K inserts/sec 13ΞΌs Cassandra-like (CQL)

🎯 Key Features

πŸ”‘ Key-Value Store

  • βœ… 319K ops/sec read throughput
  • βœ… 151K ops/sec write throughput
  • βœ… Sub-10ΞΌs latency
  • βœ… Atomic batch operations (MSET/MGET/MDEL)
  • βœ… Dual storage: Disk (durable) or Memory (fastest)
  • βœ… Text + Binary protocols with auto-detection
  • βœ… Distributed clustering with Raft consensus

πŸ“¬ Message Queue

  • βœ… 104K ops/sec push throughput
  • βœ… 100K ops/sec pop throughput
  • βœ… Unified Port: Runs on same port as KV (7380)
  • βœ… Durable: Backed by BadgerDB
  • βœ… Atomic: Crash-safe metadata management
  • βœ… Multiple queues with independent operations

🌊 Stream Processing

  • βœ… Kafka-like pub/sub messaging
  • βœ… Partitioned topics for scalability
  • βœ… Consumer groups with automatic rebalancing
  • βœ… Offset management for reliable delivery
  • βœ… Retention policies for automatic cleanup
  • βœ… At-least-once delivery semantics

�️ Wide-Column Database

  • βœ… 76K inserts/sec throughput
  • βœ… 13ΞΌs average latency
  • βœ… Cassandra-like architecture (Partition/Clustering keys)
  • βœ… FQL (Flin Query Language) schema support (CQL-compatible)
  • βœ… Prisma-like fluent query builder
  • βœ… Efficient Deep Pagination with secondary indexes
  • βœ… Flexible storage supporting both structured and semi-structured data
  • βœ… ACID transactions via BadgerDB

πŸ—οΈ Architecture

Flin uses a modular, layered architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Client SDKs (Go, Python, etc)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Binary Protocol (Auto-detection)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Server Layer (Hybrid: Fast Path + Workers)     β”‚
β”‚  β”œβ”€ KV Handlers                                 β”‚
β”‚  β”œβ”€ Queue Handlers                              β”‚
β”‚  β”œβ”€ Stream Handlers                             β”‚
β”‚  └─ Database Handlers                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         High-Level Abstraction Layer            β”‚
β”‚  β”œβ”€ internal/kv      (KV operations)            β”‚
β”‚  β”œβ”€ internal/queue   (Queue operations)         β”‚
β”‚  β”œβ”€ internal/stream  (Stream operations)        β”‚
β”‚  └─ internal/db      (Database operations)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Storage Layer (BadgerDB)             β”‚
β”‚  β”œβ”€ internal/storage/kv.go                      β”‚
β”‚  β”œβ”€ internal/storage/queue.go                   β”‚
β”‚  β”œβ”€ internal/storage/stream.go                  β”‚
β”‚  └─ internal/storage/db.go                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        ClusterKit (Raft Consensus)              β”‚
β”‚  β”œβ”€ Leader Election                             β”‚
β”‚  β”œβ”€ Partition Management                        β”‚
β”‚  └─ Replication                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Quick Start

🐳 Docker (Recommended)

Single Node:

cd docker/single && ./run.sh

3-Node Cluster:

cd docker/cluster && ./run.sh

Both scripts automatically:

  • Start the node(s)
  • Run performance benchmarks
  • Show throughput metrics
  • Leave cluster running for testing

See docker/README.md for details.

πŸ’» Local Installation

git clone https://github.com/skshohagmiah/flin
cd flin
go build -o bin/flin-server ./cmd/server

Run Server

# Single node with all features
./bin/flin-server \
  -node-id=node1 \
  -http=:8080 \
  -raft=:9080 \
  -port=:7380 \
  -data=./data/node1 \
  -workers=256

# Join existing cluster
./bin/flin-server \
  -node-id=node2 \
  -http=:8081 \
  -raft=:9081 \
  -port=:7381 \
  -data=./data/node2 \
  -join=localhost:8080

πŸ’» Unified Client Usage

Flin provides a single, unified client for all operations.

import flin "github.com/skshohagmiah/flin/clients/go"

// Create unified client (connects to port 7380)
opts := flin.DefaultOptions("localhost:7380")
client, _ := flin.NewClient(opts)
defer client.Close()

// ============ πŸ”‘ KV Store ============
client.KV.Set("user:1", []byte("John Doe"))
value, _ := client.KV.Get("user:1")
client.KV.Delete("user:1")

// Batch operations
client.KV.MSet([]string{"k1", "k2"}, [][]byte{[]byte("v1"), []byte("v2")})
values, _ := client.KV.MGet([]string{"k1", "k2"})

// ============ πŸ“¬ Message Queue ============
client.Queue.Push("tasks", []byte("Task 1"))
client.Queue.Push("tasks", []byte("Task 2"))

msg, _ := client.Queue.Pop("tasks")
fmt.Printf("Received: %s\n", string(msg))

// ============ 🌊 Stream Processing ============
// Create topic with 4 partitions and 7 days retention
client.Stream.CreateTopic("events", 4, 7*24*60*60*1000)

// Publish messages
client.Stream.Publish("events", -1, "user123", []byte(`{"action":"login"}`))

// Subscribe consumer group
client.Stream.Subscribe("events", "processors", "worker-1")

// Consume messages
messages, _ := client.Stream.Consume("events", "processors", "worker-1", 10)
for _, msg := range messages {
    fmt.Printf("Partition %d, Offset %d: %s\n", msg.Partition, msg.Offset, msg.Value)
    // Commit offset after processing
    client.Stream.Commit("events", "processors", msg.Partition, msg.Offset+1)
}

// ============ πŸ“„ Document Database ============
// Register Schema (FQL) - Optional but recommended for performance
client.DB.RegisterFQL(`
    CREATE TABLE users (
        id uuid,
        name text,
        email text,
        age int,
        PRIMARY KEY (id)
    );
`)

// Insert document
id, _ := client.DB.Insert("users", map[string]interface{}{
    "name":  "John Doe",
    "email": "john@example.com",
    "age":   30,
})

// Find documents (Prisma-like API)
users, _ := client.DB.Query("users").
    Where("age", flin.Gte, 18).
    Where("status", flin.Eq, "active").
    OrderBy("created_at", flin.Desc).
    Skip(0).
    Take(10).
    Exec()

// Update document
client.DB.Update("users").
    Where("email", flin.Eq, "john@example.com").
    Set("age", 31).
    Set("verified", true).
    Exec()

// Delete document
client.DB.Delete("users").
    Where("status", flin.Eq, "inactive").
    Exec()

πŸ”₯ Performance Benchmarks

KV Store

cd benchmarks
./kv-throughput.sh

Results:

  • Read: 319K ops/sec (3.1ΞΌs latency)
  • Write: 151K ops/sec (6.6ΞΌs latency)
  • Batch: 792K ops/sec (1.26ΞΌs latency)

Message Queue

./queue-throughput.sh

Results:

  • Push: 104K ops/sec (9.6ΞΌs latency)
  • Pop: 100K ops/sec (10ΞΌs latency)

Stream Processing

./stream-throughput.sh

Results:

  • High throughput pub/sub
  • Efficient partition management
  • Low-latency message delivery

Document Database

./db-throughput.sh

Results:

  • Insert: 76K docs/sec (13ΞΌs latency)
  • Query: Fast with secondary indexes
  • Update: Efficient in-place updates

πŸ“Š Performance vs Redis

Operation Flin Redis Speedup
KV Read 319K/s ~100K/s 3.2x
KV Write 151K/s ~80K/s 1.9x
Queue Push 104K/s ~80K/s 1.3x
Queue Pop 100K/s ~80K/s 1.25x
Batch Ops 792K/s ~100K/s 7.9x

πŸ› οΈ Configuration

Server Options

Flag Default Description
-node-id (required) Unique node identifier
-http :8080 HTTP API address
-raft :9080 Raft consensus address
-port :7380 Unified server port (KV+Queue+Stream+Doc)
-data ./data Data directory
-workers 64 Worker pool size
-partitions 64 Number of partitions
-memory false Use in-memory storage (no persistence)
-join (empty) Address of node to join

Storage Modes

Disk Mode (Default):

  • Durable persistence via BadgerDB
  • Survives restarts
  • Optimized for throughput

Memory Mode:

  • Fastest performance
  • Data lost on restart
  • Use for caching/temporary data
# Memory mode
./bin/flin-server -node-id=node1 -port=:7380 -memory

πŸ›οΈ Project Structure

flin/
β”œβ”€β”€ cmd/
β”‚   └── server/          # Server entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ kv/              # KV store abstraction
β”‚   β”œβ”€β”€ queue/           # Queue abstraction
β”‚   β”œβ”€β”€ stream/          # Stream abstraction
β”‚   β”œβ”€β”€ db/              # Document store abstraction
β”‚   β”‚   β”œβ”€β”€ types.go     # Type definitions
β”‚   β”‚   β”œβ”€β”€ query.go     # Query builder
β”‚   β”‚   β”œβ”€β”€ helpers.go   # Utility functions
β”‚   β”‚   └── db.go        # Main implementation
β”‚   β”œβ”€β”€ storage/         # Storage layer
β”‚   β”‚   β”œβ”€β”€ kv.go        # KV BadgerDB ops
β”‚   β”‚   β”œβ”€β”€ queue.go     # Queue BadgerDB ops
β”‚   β”‚   β”œβ”€β”€ stream.go    # Stream BadgerDB ops
β”‚   β”‚   └── db.go        # Document BadgerDB ops
β”‚   β”œβ”€β”€ server/          # Server handlers
β”‚   β”œβ”€β”€ protocol/        # Binary protocol
β”‚   └── net/             # Connection pooling
β”œβ”€β”€ clients/
β”‚   └── go/              # Go client SDK
β”œβ”€β”€ benchmarks/          # Performance tests
└── docker/              # Docker configs

πŸ” Clustering & Replication

Flin uses Raft consensus for:

  • Leader election
  • Log replication
  • Partition management
  • Automatic failover

3-Node Cluster Example:

# Node 1 (bootstrap)
./bin/flin-server -node-id=node1 -http=:8080 -raft=:9080 -port=:7380

# Node 2 (join)
./bin/flin-server -node-id=node2 -http=:8081 -raft=:9081 -port=:7381 -join=localhost:8080

# Node 3 (join)
./bin/flin-server -node-id=node3 -http=:8082 -raft=:9082 -port=:7382 -join=localhost:8080

πŸ“š Documentation

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE for details

πŸ™ Acknowledgments

  • Built with BadgerDB for storage
  • Uses ClusterKit for Raft consensus
  • Inspired by Redis, Kafka, and MongoDB

Made with ❀️ by the Flin team

About

FLIN : A blazing-fast, distributed data platform combining Key-Value Store, Message Queue, Stream Processing, and Document Database in a single unified system.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •