# microsoft/garnet architecture

> Architecture diagram of the GitHub repository microsoft/garnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/garnet
- Repository: https://github.com/microsoft/garnet

## Overview

Garnet is a RESP-compatible remote cache-store. The principal workflow is: an application uses a Garnet client, the server accepts and parses RESP commands, authenticates and dispatches them, storage sessions execute operations against Tsavorite-backed databases, and responses return through the same network path. Major branches include transactions, durability and tiered devices, object/vector/range features, extensibility, and passive clustered sharding, migration, gossip, and replication. Some subsystem links reflect README capabilities because their implementations were not sampled directly.

Main entry points: [`libs/server/Resp/RespServerSession.cs`](https://github.com/microsoft/garnet/blob/main/libs/server/Resp/RespServerSession.cs) (RESP Session), [`libs/cluster/Session/ClusterSession.cs`](https://github.com/microsoft/garnet/blob/main/libs/cluster/Session/ClusterSession.cs) (Cluster Session), [`libs/server/Databases/MultiDatabaseManager.cs`](https://github.com/microsoft/garnet/blob/main/libs/server/Databases/MultiDatabaseManager.cs) (Database Manager), [`libs/client/GarnetClient.cs`](https://github.com/microsoft/garnet/blob/main/libs/client/GarnetClient.cs) (Garnet Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Client Access"]
  node_client["Garnet Client<br/>[GarnetClient.cs]"]
end

subgraph group_runtime["Server Runtime"]
  node_server["TCP Server<br/>[GarnetServerTcp.cs]"]
  node_resp["RESP Session"]
  node_auth["Authentication ACL"]
  node_storage_session["Storage Session<br/>[StorageSession.cs]"]
end

subgraph group_storage["Storage Durability"]
  node_db_manager["Database Manager"]
  node_database[("Garnet Database<br/>[GarnetDatabase.cs]")]
  node_provider["Tsavorite Provider<br/>[GarnetProvider.cs]"]
  node_checkpoint["Checkpoint Manager"]
  node_aof[("AOF Durability")]
  node_device_factory["Device Factory"]
  node_native_device["Native File Device"]
  node_azure_device["Azure Device"]
end

subgraph group_features["Data Features"]
  node_transactions["Transaction Manager"]
  node_vectors["Vector Manager<br/>[VectorManager.cs]"]
  node_diskann["DiskANN Service<br/>[DiskANNService.cs]"]
  node_range_index["Range Index"]
  node_bftree["BfTree Native"]
  node_custom["Custom Commands"]
  node_lua["Lua Runner<br/>[LuaRunner.cs]"]
end

subgraph group_cluster["Cluster Operations"]
  node_cluster_session["Cluster Session<br/>[ClusterSession.cs]"]
  node_cluster_manager["Cluster Manager<br/>[ClusterManager.cs]"]
  node_slot_state["Slot State"]
  node_replication["Replication Manager"]
  node_gossip["Gossip Service<br/>[Gossip.cs]"]
  node_migration["Key Migration<br/>[MigrateCommand.cs]"]
end

node_application(("Application"))
node_controlplane(("Control Plane"))
node_azure[("Azure Blob Storage")]

node_application -->|"uses client"| node_client
node_client -->|"sends RESP"| node_server
node_server -->|"accepts sessions"| node_resp
node_resp -->|"authenticates"| node_auth
node_resp -->|"dispatches commands"| node_storage_session
node_resp -->|"runs transactions"| node_transactions
node_resp -->|"dispatches extensions"| node_custom
node_resp -->|"runs scripts"| node_lua
node_resp -->|"dispatches cluster"| node_cluster_session
node_storage_session -->|"selects database"| node_db_manager
node_db_manager -->|"retrieves database"| node_database
node_database -->|"uses stores"| node_provider
node_storage_session -->|"opens vector context"| node_vectors
node_vectors -->|"updates index"| node_diskann
node_resp -->|"runs range queries"| node_range_index
node_range_index -->|"uses index"| node_bftree
node_transactions -->|"logs transaction"| node_aof
node_db_manager -->|"takes checkpoints"| node_checkpoint
node_db_manager -->|"recovers AOF"| node_aof
node_device_factory -->|"creates device"| node_native_device
node_device_factory -.->|"selects cloud device"| node_azure_device
node_native_device -->|"persists segments"| node_database
node_azure_device -.->|"reads writes blobs"| node_azure
node_controlplane -->|"issues commands"| node_cluster_session
node_cluster_session -->|"manages cluster"| node_cluster_manager
node_cluster_manager -->|"updates slots"| node_slot_state
node_cluster_session -->|"migrates keys"| node_migration
node_cluster_session -->|"controls replication"| node_replication
node_cluster_manager -->|"shares state"| node_gossip
node_resp -->|"returns replies"| node_client
node_client -->|"returns results"| node_application

click node_client "https://github.com/microsoft/garnet/blob/main/libs/client/GarnetClient.cs"
click node_server "https://github.com/microsoft/garnet/blob/main/libs/server/Servers/GarnetServerTcp.cs"
click node_resp "https://github.com/microsoft/garnet/blob/main/libs/server/Resp/RespServerSession.cs"
click node_auth "https://github.com/microsoft/garnet/blob/main/libs/server/Auth/GarnetACLAuthenticator.cs"
click node_storage_session "https://github.com/microsoft/garnet/blob/main/libs/server/Storage/Session/StorageSession.cs"
click node_db_manager "https://github.com/microsoft/garnet/blob/main/libs/server/Databases/MultiDatabaseManager.cs"
click node_database "https://github.com/microsoft/garnet/blob/main/libs/server/GarnetDatabase.cs"
click node_provider "https://github.com/microsoft/garnet/blob/main/libs/server/Providers/GarnetProvider.cs"
click node_checkpoint "https://github.com/microsoft/garnet/blob/main/libs/server/GarnetCheckpointManager.cs"
click node_aof "https://github.com/microsoft/garnet/blob/main/libs/server/AOF/GarnetAppendOnlyFile.cs"
click node_device_factory "https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/core/Index/CheckpointManagement/LocalStorageNamedDeviceFactory.cs"
click node_native_device "https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/core/Device/NativeStorageDevice.cs"
click node_azure_device "https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/AzureStorageDevice.cs"
click node_transactions "https://github.com/microsoft/garnet/blob/main/libs/server/Transaction/TransactionManager.cs"
click node_vectors "https://github.com/microsoft/garnet/blob/main/libs/server/Resp/Vector/VectorManager.cs"
click node_diskann "https://github.com/microsoft/garnet/blob/main/libs/server/Resp/Vector/DiskANNService.cs"
click node_range_index "https://github.com/microsoft/garnet/blob/main/libs/server/Resp/RangeIndex/RangeIndexManager.cs"
click node_bftree "https://github.com/microsoft/garnet/blob/main/libs/native/bftree-garnet/NativeBfTreeMethods.cs"
click node_custom "https://github.com/microsoft/garnet/blob/main/libs/server/Custom/CustomCommandManager.cs"
click node_lua "https://github.com/microsoft/garnet/blob/main/libs/server/Lua/LuaRunner.cs"
click node_cluster_session "https://github.com/microsoft/garnet/blob/main/libs/cluster/Session/ClusterSession.cs"
click node_cluster_manager "https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/ClusterManager.cs"
click node_slot_state "https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/ClusterManagerSlotState.cs"
click node_replication "https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/Replication/ReplicationManager.cs"
click node_gossip "https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/Gossip/Gossip.cs"
click node_migration "https://github.com/microsoft/garnet/blob/main/libs/cluster/Session/MigrateCommand.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client toneBlue
class node_server,node_resp,node_auth,node_storage_session,node_azure toneAmber
class node_db_manager,node_database,node_provider,node_checkpoint,node_aof,node_device_factory,node_native_device,node_azure_device toneMint
class node_transactions,node_vectors,node_diskann,node_range_index,node_bftree,node_custom,node_lua toneRose
class node_cluster_session,node_cluster_manager,node_slot_state,node_replication,node_gossip,node_migration,node_application,node_controlplane toneIndigo
```

## Components

### Client Access

- [Garnet Client](https://github.com/microsoft/garnet/blob/main/libs/client/GarnetClient.cs): `libs/client/GarnetClient.cs`

### Server Runtime

- [TCP Server](https://github.com/microsoft/garnet/blob/main/libs/server/Servers/GarnetServerTcp.cs): `libs/server/Servers/GarnetServerTcp.cs`
- [RESP Session](https://github.com/microsoft/garnet/blob/main/libs/server/Resp/RespServerSession.cs): `libs/server/Resp/RespServerSession.cs`
- [Authentication ACL](https://github.com/microsoft/garnet/blob/main/libs/server/Auth/GarnetACLAuthenticator.cs): `libs/server/Auth/GarnetACLAuthenticator.cs`
- [Storage Session](https://github.com/microsoft/garnet/blob/main/libs/server/Storage/Session/StorageSession.cs): `libs/server/Storage/Session/StorageSession.cs`

### Storage Durability

- [Database Manager](https://github.com/microsoft/garnet/blob/main/libs/server/Databases/MultiDatabaseManager.cs): `libs/server/Databases/MultiDatabaseManager.cs`
- [Garnet Database](https://github.com/microsoft/garnet/blob/main/libs/server/GarnetDatabase.cs): `libs/server/GarnetDatabase.cs`
- [Tsavorite Provider](https://github.com/microsoft/garnet/blob/main/libs/server/Providers/GarnetProvider.cs): `libs/server/Providers/GarnetProvider.cs`
- [Checkpoint Manager](https://github.com/microsoft/garnet/blob/main/libs/server/GarnetCheckpointManager.cs): `libs/server/GarnetCheckpointManager.cs`
- [AOF Durability](https://github.com/microsoft/garnet/blob/main/libs/server/AOF/GarnetAppendOnlyFile.cs): `libs/server/AOF/GarnetAppendOnlyFile.cs`
- [Device Factory](https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/core/Index/CheckpointManagement/LocalStorageNamedDeviceFactory.cs): `libs/storage/Tsavorite/cs/src/core/Index/CheckpointManagement/LocalStorageNamedDeviceFactory.cs`
- [Native File Device](https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/core/Device/NativeStorageDevice.cs): `libs/storage/Tsavorite/cs/src/core/Device/NativeStorageDevice.cs`
- [Azure Device](https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/AzureStorageDevice.cs): `libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/AzureStorageDevice.cs`

### Data Features

- [Transaction Manager](https://github.com/microsoft/garnet/blob/main/libs/server/Transaction/TransactionManager.cs): `libs/server/Transaction/TransactionManager.cs`
- [Vector Manager](https://github.com/microsoft/garnet/blob/main/libs/server/Resp/Vector/VectorManager.cs): `libs/server/Resp/Vector/VectorManager.cs`
- [DiskANN Service](https://github.com/microsoft/garnet/blob/main/libs/server/Resp/Vector/DiskANNService.cs): `libs/server/Resp/Vector/DiskANNService.cs`
- [Range Index](https://github.com/microsoft/garnet/blob/main/libs/server/Resp/RangeIndex/RangeIndexManager.cs): `libs/server/Resp/RangeIndex/RangeIndexManager.cs`
- [BfTree Native](https://github.com/microsoft/garnet/blob/main/libs/native/bftree-garnet/NativeBfTreeMethods.cs): `libs/native/bftree-garnet/NativeBfTreeMethods.cs`
- [Custom Commands](https://github.com/microsoft/garnet/blob/main/libs/server/Custom/CustomCommandManager.cs): `libs/server/Custom/CustomCommandManager.cs`
- [Lua Runner](https://github.com/microsoft/garnet/blob/main/libs/server/Lua/LuaRunner.cs): `libs/server/Lua/LuaRunner.cs`

### Cluster Operations

- [Cluster Session](https://github.com/microsoft/garnet/blob/main/libs/cluster/Session/ClusterSession.cs): `libs/cluster/Session/ClusterSession.cs`
- [Cluster Manager](https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/ClusterManager.cs): `libs/cluster/Server/ClusterManager.cs`
- [Slot State](https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/ClusterManagerSlotState.cs): `libs/cluster/Server/ClusterManagerSlotState.cs`
- [Replication Manager](https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/Replication/ReplicationManager.cs): `libs/cluster/Server/Replication/ReplicationManager.cs`
- [Gossip Service](https://github.com/microsoft/garnet/blob/main/libs/cluster/Server/Gossip/Gossip.cs): `libs/cluster/Server/Gossip/Gossip.cs`
- [Key Migration](https://github.com/microsoft/garnet/blob/main/libs/cluster/Session/MigrateCommand.cs): `libs/cluster/Session/MigrateCommand.cs`

### Other components

- **Application**
- **Control Plane**
- **Azure Blob Storage**

## Connections

- Application → Garnet Client: uses client
- Garnet Client → TCP Server: sends RESP
- TCP Server → RESP Session: accepts sessions
- RESP Session → Authentication ACL: authenticates
- RESP Session → Storage Session: dispatches commands
- RESP Session → Transaction Manager: runs transactions
- RESP Session → Custom Commands: dispatches extensions
- RESP Session → Lua Runner: runs scripts
- RESP Session → Cluster Session: dispatches cluster
- Storage Session → Database Manager: selects database
- Database Manager → Garnet Database: retrieves database
- Garnet Database → Tsavorite Provider: uses stores
- Storage Session → Vector Manager: opens vector context
- Vector Manager → DiskANN Service: updates index
- RESP Session → Range Index: runs range queries
- Range Index → BfTree Native: uses index
- Transaction Manager → AOF Durability: logs transaction
- Database Manager → Checkpoint Manager: takes checkpoints
- Database Manager → AOF Durability: recovers AOF
- Device Factory → Native File Device: creates device
- Device Factory → Azure Device: selects cloud device
- Native File Device → Garnet Database: persists segments
- Azure Device → Azure Blob Storage: reads writes blobs
- Control Plane → Cluster Session: issues commands
- Cluster Session → Cluster Manager: manages cluster
- Cluster Manager → Slot State: updates slots
- Cluster Session → Key Migration: migrates keys
- Cluster Session → Replication Manager: controls replication
- Cluster Manager → Gossip Service: shares state
- RESP Session → Garnet Client: returns replies
- Garnet Client → Application: returns results
