DEV Community

Alex Spinov
Alex Spinov

Posted on

Garnet Has a Free Redis-Compatible Cache From Microsoft — Built on .NET

Microsoft built their own Redis alternative. It's open-source, runs on .NET, and outperforms Redis on their benchmarks.

What is Garnet?

Garnet is a remote cache-store from Microsoft Research, compatible with Redis's RESP protocol. Built on .NET, it's designed for high throughput and low latency, especially on cloud VMs.

Why Microsoft Built Garnet

1. Redis API Compatible

import redis
r = redis.Redis(host='localhost', port=6379)

# Standard Redis commands
r.set('session:abc', json.dumps({'user': 'alice'}))
r.get('session:abc')
r.hset('user:1', mapping={'name': 'Alice', 'score': '100'})
r.lpush('events', 'login', 'pageview')
Enter fullscreen mode Exit fullscreen mode

2. Designed for Cloud VMs

Garnet is optimized for modern cloud hardware:

  • Uses all CPU cores efficiently
  • Minimizes memory allocations (less GC pressure)
  • Optimized for NUMA architectures
  • Supports tiered storage (RAM + SSD)

3. Thread-Scalable Architecture

# Garnet scales linearly with cores
# 4 cores:  400K ops/sec
# 16 cores: 1.5M ops/sec
# 64 cores: 5M+ ops/sec
Enter fullscreen mode Exit fullscreen mode

4. Cluster Mode

# Start with cluster mode
GarnetServer --cluster-enabled
Enter fullscreen mode Exit fullscreen mode

Supports Redis cluster protocol for horizontal scaling.

5. Custom Extensions

// Write custom commands in C#
public class MyCommand : CustomRawStringCommand
{
    public override bool Execute(
        IGarnetApi garnetApi,
        ref RawStringInput input,
        ref GarnetObjectStoreOutput output)
    {
        // Custom logic with full access to the store
        garnetApi.SET(key, value);
        return true;
    }
}
Enter fullscreen mode Exit fullscreen mode

Extend Garnet with C# — no Lua scripting limitations.

Performance

Benchmark Redis 7 Garnet
GET (single thread) 100K/s 120K/s
GET (16 threads) 100K/s 1.2M/s
SET (batch) 450K/s 2.1M/s
Latency P99 0.5ms 0.3ms

Garnet vs Redis vs Dragonfly

Garnet Redis Dragonfly
Runtime .NET C C++
Threading Multi-threaded Single Shared-nothing
Extensions C# Lua No
License MIT SSPL BSL
Tiered storage Yes No Yes
Maintainer Microsoft Redis Ltd DragonflyDB

Getting Started

# Docker
docker run -p 6379:6379 ghcr.io/microsoft/garnet

# From source
git clone https://github.com/microsoft/garnet.git
cd garnet
dotnet restore
dotnet run -c Release -f net8.0 --project main/GarnetServer
Enter fullscreen mode Exit fullscreen mode

The Bottom Line

Garnet brings .NET's reliability and Microsoft's backing to the cache-store world. MIT-licensed, Redis-compatible, and designed for modern cloud hardware.


Need data solutions? I build scraping tools. Check my Apify actors or email spinov001@gmail.com.

Top comments (0)