Skip to content

sdwck/ToggleMesh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ToggleMesh Logo

ToggleMesh

Enterprise Feature Flag & Contextual Experimentation Engine

A high-performance, data-private, self-hosted alternative to LaunchDarkly and Statsig. Powered by .NET Core, featuring native SDKs for C#, Python, Go, Node.js, and C++.

Status Build Status .NET 10 <25ns Latency 0 Bytes Allocated MIT License

ToggleMesh Admin Dashboard
Manage environments, targeting rules, and A/B tests from a unified, modern interface.


πŸ“– What is ToggleMesh?

ToggleMesh is a self-hosted feature management and experimentation platform designed for teams that require strict data privacy, enterprise-grade RBAC, and ultra-low latency.

Unlike SaaS providers that charge by MAU or require your application to make network calls for flag evaluation, ToggleMesh pushes configurations directly to your servers. Your SDKs evaluate rules locally in memory, ensuring zero network overhead and keeping 100% of your user context within your private infrastructure.

How it compares

Feature ToggleMesh LaunchDarkly Statsig Unleash
Full Self-Hosting βœ… ❌ (Relay only) ❌ βœ…
Data Privacy (No PII leaves network) βœ… ❌ ❌ βœ…
Zero-Allocation Eval (.NET) βœ… ❌ ❌ ❌
Built-in MAB A/B Tests βœ… ❌ βœ… ❌
Real-Time Push βœ… (SSE) βœ… βœ… ⚠️ (Polling)
Pricing Free (MIT) Per-seat Per-MAU Freemium

πŸ—οΈ Architecture

flowchart TD
    classDef ui fill:#18181b,stroke:#3f3f46,stroke-width:2px,color:#f4f4f5;
    classDef api fill:#0f172a,stroke:#6366f1,stroke-width:2px,color:#f4f4f5;
    classDef db fill:#312e81,stroke:#818cf8,stroke-width:2px,color:#f4f4f5;
    classDef cache fill:#7f1d1d,stroke:#f87171,stroke-width:2px,color:#f4f4f5;
    classDef sdk fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#f4f4f5;
    classDef worker fill:#4c1d95,stroke:#a5b4fc,stroke-width:2px,color:#f4f4f5;

    UI[React Admin UI]:::ui -- REST / JWT --> API["ToggleMesh.API<br/>(Management & SSE)"]:::api
    
    API -- Read / Write --> PG[(PostgreSQL)]:::db
    API -- EF Interceptor Publish --> REDIS[(Redis Pub/Sub)]:::cache
    REDIS -. Fan-out Invalidate .-> API
    
    API == SSE Push ==> SDK["Client & Server SDKs<br/>(Zero-Alloc Eval)"]:::sdk

    SDK -- Async Batch Events --> INGEST["ToggleMesh.API<br/>(Ingest Endpoint)"]:::api

    subgraph Analytics Pipeline
        direction LR
        INGEST -- Stream --> KAFKA[(Kafka / Channels)]:::db
        KAFKA -- Consume --> CH[(ClickHouse OLAP)]:::db
        CH -- Bayesian Query --> WORKER[MAB Rollup Worker]:::worker
    end

    WORKER -. Auto-adjust traffic .-> PG
Loading

Control Plane mutates state -> Interceptor triggers Redis Pub/Sub -> API fans out SSE to connected SDKs.


πŸ‘¨β€πŸ’» Quick Start

Prerequisite: A running ToggleMesh server instance. See Self-Hosting & Deployment to spin one up locally in under a minute.

Step 0: Install the Tools

Install the C# SDK and the Global CLI tool:

dotnet add package ToggleMesh.SDK
dotnet tool install --global ToggleMesh.CLI

Step 1: Zero-Config Context Injection

Register the SDK in your DI container. ToggleMesh can automatically hook into your ambient HttpContext to extract user identity, emails, and roles without manual context passing.

// Program.cs
builder.Services.AddToggleMeshClient(options => 
{
    options.BaseUrl = "https://api.togglemesh.dev"; // Your self-hosted Control Plane
    options.ApiKey = "tm_server_xxxxxxxx";
}).AddToggleMeshHttpContext(); 

Step 2: Sync Constants & Evaluate

Sync your flags to generate type-safe constants, then evaluate them in your business logic.

$ togglemesh config
$ togglemesh sync
βœ” Success! Auto-detected C# project. Generated ToggleMeshFlags.g.cs
// CheckoutService.cs
public void ProcessOrder(IToggleMeshClient toggleMesh) 
{
    // Evaluates instantly from in-memory cache. Zero HTTP requests made.
    if (toggleMesh.IsEnabled(Flags.NewCheckoutFlow)) 
    {
        ExecuteNextGenGateway();
    }
}

⚑ The Sub-25ns Evaluation Engine (Performance Proof)

ToggleMesh is engineered for ultra-low-latency microservices where Garbage Collection (GC) pauses are unacceptable.

By leveraging compiled Expression Trees, pre-computed rule groups, C# Source Generators, and readonly ref struct contexts, the ToggleMesh SDK achieves zero-allocation evaluation.

BenchmarkDotNet Results

We benchmarked various scenarios: from a simple global toggle to a worst-case scenario evaluating 10 nested AND/OR targeting rules.

Method Mean StdDev Max P95 Allocated
IsEnabled_NoRules_AOT (Baseline) 17.34 ns 0.026 ns 17.39 ns 17.38 ns -
IsEnabled_With1Rule_AOT (Typical) 22.49 ns 0.055 ns 22.55 ns 22.55 ns -
IsEnabled_Complex_AOT (MAB/Rollout) 81.44 ns 0.160 ns 81.82 ns 81.74 ns -
IsEnabled_With10Rules_AOT (Worst-case) 127.14 ns 0.664 ns 128.12 ns 127.93 ns -
Track_Event (Metrics Buffer) 41.58 ns 0.071 ns 41.69 ns 41.69 ns -

Hardware Specs: Intel Core i7-14700K, 20 Physical Cores, Windows 11 x64, .NET 10.0 Release Build.

Extreme High-Throughput (Load Testing)

ToggleMesh decouples heavy I/O operations from the HTTP request-response cycle using bounded in-memory channels (System.Threading.Channels) with DropOldest backpressure.

Local load testing via k6 on a single developer workstation demonstrates the massive throughput capabilities of the Data Plane API.

Endpoint Type Target VUs Max RPS p(99) Tail Latency Error Rate
POST /api/v1/sdk/metrics Fire & Forget (Channel) 2,000 115,248/s 18.59 ms 0.00%
POST /api/v1/sdk/evaluate Synchronous (Compute) 2,000 112,503/s 19.22 ms 0.00%
POST /api/v1/sdk/events Buffered + Livetail (SSE) 2,000 68,301/s 34.58 ms 0.00%
GET /api/v1/sdk/flags Synchronous (I/O Cache) 2,000 68,463/s 36.06 ms 0.00%

Test Environment: Intel Core i7-14700K, k6 running locally against Kestrel (Release mode, HTTP). All tests maintained a flawless 0.00% failure rate under sustained load. Data payload bandwidth maxed out at ~179 MB/s during sync.


πŸ’» Ecosystem & Supported SDKs

ToggleMesh provides native SDKs and tooling for your entire microservice fleet.

Language / Platform SDK Type Real-Time Sync Targeting Evaluation Maturity
.NET (C#) Server βœ… (SSE) Local (Zero-Alloc) Stable
Node.js Server βœ… (SSE) Local Beta
Browser JS / React Client βœ… (SSE) Remote (Secure) Beta
Python Server βœ… (SSE) Local Beta
Go Server βœ… (SSE) Local MVP
Unreal Engine (C++) Game Client πŸ”„ (Polling) Remote MVP

🏒 Enterprise-Grade Features

  • πŸ“‘ Push, Not Pull (SSE + Redis): Real-time cache invalidation using Server-Sent Events. No wasteful HTTP polling.
  • 🧠 Contextual Multi-Armed Bandits (MAB): Built-in Bayesian inference engine (Monte Carlo simulations via Beta distributions). Autonomously shifts traffic toward winning variants based on conversion or revenue metrics.
  • πŸ“ˆ High-Throughput Analytics Ingestion: SDKs buffer metrics client-side. The API ingests telemetry into bounded System.Threading.Channels with DropOldest backpressure, flushing to PostgreSQL or horizontally scalable Kafka + ClickHouse clusters.
  • πŸ” Multi-Tenancy & RBAC: Organization and Project-level isolation with strict Role-Based Access Control.
  • πŸ”‘ Personal Access Tokens (PATs): SHA-256 hashed PATs for secure CI/CD and CLI integrations.
  • πŸ›‘οΈ SSRF-Protected Webhooks: Secure outbound webhook dispatcher with Polly-powered exponential backoff and Dead-Letter Queues (DLQ).
  • πŸ“œ Immutable Audit Logs: EF Core SaveChangesInterceptors capture deep JSON diffs of every mutation.
  • πŸ’Ύ Offline Resilience: SDKs persist the latest synchronized state to a local JSON fallback file, ensuring safe boot-ups during complete network partitions.

🐳 Self-Hosting & Deployment

Quick Start (PostgreSQL + Redis)

Deploying the core ToggleMesh stack takes under a minute.

git clone https://github.com/sdwck/ToggleMesh.git
cd ToggleMesh
cp .env.example .env    # Review and customize your secrets here
docker compose up -d
  • Admin UI: http://localhost:5173
  • API: http://localhost:5264
  • API Docs (Scalar): http://localhost:5264/docs

Enterprise Stack (+ Kafka & ClickHouse)

For production deployments requiring high-throughput analytics and horizontal OLAP scaling, boot the stack using the enterprise override:

docker compose -f docker-compose.yml -f docker-compose.enterprise.yml up -d

🀝 Contributing & License

ToggleMesh is released under the MIT License.
Contributions are welcome β€” please read our Contributing Guidelines before opening a PR.


⭐ If ToggleMesh looks useful, star this repo β€” it helps others discover it.
Report a Bug Β· Request a Feature

About

Enterprise-grade, zero-allocation feature flag and A/B testing engine. Built in .NET for ultimate performance, designed for polyglot distributed systems.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors