# buraksezer/olric architecture

> Architecture diagram of the GitHub repository buraksezer/olric, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/buraksezer/olric
- Repository: https://github.com/buraksezer/olric

## Overview

##### Main Components

a) Core Services Layer:
- DMap Service (distributed map implementation)
- PubSub Service (publish/subscribe messaging)
- Storage Engine (in-memory storage with GC-friendly design)
- Lock Service (distributed locking mechanism)

b) Cluster Management Layer:
- Membership Management (using hashicorp/memberlist)
- Partition Management
- Rebalancer Component
- Routing Table Management

c) Network Layer:
- Redis Protocol Server
- Member Communication Server
- Client Interface

##### Key Relationships

a) Data Flow:
- Client requests → Redis Protocol Server → DMap/PubSub Services
- Inter-node communication paths
- Replication flows between primary and backup nodes

b) Control Flow:
- Cluster membership changes
- Partition rebalancing operations
- Lock acquisition/release paths

##### Architectural Patterns to Highlight

- Primary-Backup Replication Model
- Consistent Hashing for Partition Distribution
- Optimistic Replication Strategy
- Read-Repair Mechanism

##### Key Elements to Label

- Partition IDs
- Primary/Backup relationships
- Protocol endpoints
- Service discovery interfaces
- Eviction policy handlers

##### Technical Details

- TCP ports (3320 for client, 3322 for memberlist)
- Partition count
- Replication factors
- Quorum configurations

##### Deployment Scenarios

- Embedded mode deployment
- Client-server mode deployment
- Multi-node cluster configuration

- Partition distribution
- Data replication
- Failure detection
- Split-brain protection
- Read/Write quorum implementation

This system design should reflect Olric's architecture as a distributed, in-memory key/value store with strong focus on scalability and availability while maintaining eventual consistency guarantees.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CI[Client Interface]:::client
        CC[Cluster Client]:::client
    end

    subgraph "Network Layer"
        RPS[Redis Protocol Server]:::network
        MCS[Member Communication Server]:::network
        PC[Protocol Commands]:::network
    end

    subgraph "Core Services"
        DMS[DMap Service]:::core
        PBS[PubSub Service]:::core
        SE[Storage Engine]:::core
        LS[Lock Service]:::core
        KVS[Key-Value Store]:::core
    end

    subgraph "Cluster Management"
        MM[Membership Management]:::cluster
        PM[Partition Management]:::cluster
        RC[Rebalancer Component]:::cluster
        RTM[Routing Table Management]:::cluster
    end

    subgraph "Configuration"
        CM[Configuration Management]:::config
    end

    %% Core relationships
    CI --> RPS
    CC --> RPS
    RPS --> PC
    PC --> DMS
    PC --> PBS
    
    DMS --> SE
    PBS --> SE
    KVS --> SE
    
    DMS --> LS
    
    %% Cluster management relationships
    MM --> RC
    PM --> RC
    RC --> RTM
    
    %% Network relationships
    MCS --> MM
    RTM --> DMS
    RTM --> PBS
    
    %% Configuration relationships
    CM --> DMS
    CM --> PBS
    CM --> MM
    
    %% Styling
    classDef core fill:#2374ab
    classDef network fill:#ff7f50
    classDef cluster fill:#4caf50
    classDef client fill:#9c27b0
    classDef config fill:#607d8b

    %% Click events
    click DMS "https://github.com/buraksezer/olric/blob/master/internal/dmap/dmap.go"
    click PBS "https://github.com/buraksezer/olric/blob/master/internal/pubsub/service.go"
    click SE "https://github.com/buraksezer/olric/blob/master/pkg/storage/engine.go"
    click LS "https://github.com/buraksezer/olric/blob/master/internal/locker/locker.go"
    click MM "https://github.com/buraksezer/olric/blob/master/internal/discovery/discovery.go"
    click PM "https://github.com/buraksezer/olric/blob/master/internal/cluster/partitions/partitions.go"
    click RC "https://github.com/buraksezer/olric/blob/master/internal/cluster/balancer/balancer.go"
    click RTM "https://github.com/buraksezer/olric/blob/master/internal/cluster/routingtable/routingtable.go"
    click RPS "https://github.com/buraksezer/olric/blob/master/internal/resp/encoder.go"
    click CI "https://github.com/buraksezer/olric/blob/master/client.go"
    click CC "https://github.com/buraksezer/olric/blob/master/cluster_client.go"
    click KVS "https://github.com/buraksezer/olric/blob/master/internal/kvstore/kvstore.go"
    click PC "https://github.com/buraksezer/olric/blob/master/internal/protocol/commands.go"
    click CM "https://github.com/buraksezer/olric/blob/master/config/config.go"
```
