Architecture

A high-level overview of how Rollgate works: components, data flow, and design decisions.

System Overview

Rollgate is designed as a multi-tenant SaaS with a clear separation between the control plane (Dashboard + API) and the data plane (SDKs).

Rollgate System Architecture

Core Components

Dashboard

Web interface for managing feature flags, built with Next.js.

  • • Create and manage flags
  • • Configure targeting rules
  • • View analytics and audit logs
  • • Manage team members and API keys

REST API

Core backend service handling all operations, built with Go.

  • • Flag CRUD operations
  • • User authentication (email, OAuth)
  • • SDK endpoints for flag evaluation
  • • Webhook triggers on flag changes

SDKs

Client libraries for integrating flags into your application.

  • • React, Vue, Angular, Svelte, Browser (frontend)
  • • Node.js, Go, Python, Java, .NET (backend)
  • • React Native, Flutter (mobile)
  • • Built-in caching and resilience
  • • Real-time updates via SSE or polling

Data Layer

Persistent storage and caching for reliability and performance.

  • • PostgreSQL: flags, users, organizations
  • • Redis: caching, pub/sub for SSE
  • • In-memory cache in SDK (stale-while-revalidate)

Data Model

Rollgate uses a hierarchical data model that mirrors how teams organize their work.

Rollgate Data Model

Key Design Decisions

  • Flags are global to a project - The same flag key exists across all environments. Only the state (enabled, rollout) varies per environment.
  • Environment-specific configuration - Each environment has its own flag states, allowing different settings for staging vs production.
  • Soft deletes - Flags and users are soft-deleted to preserve audit history and allow recovery.

Flag Evaluation Flow

When your application checks a flag, here's what happens under the hood:

1

SDK Cache Check

The SDK first checks its local cache. If fresh data exists, it returns immediately (sub-millisecond latency).

2

API Request (if needed)

If cache is stale or empty, SDK calls GET /api/v1/sdk/flags with user context.

3

Server-Side Evaluation

API evaluates all flags for the user: checks enabled state, target users, targeting rules, and rollout percentage.

4

Response with ETag

API returns evaluated flags with an ETag header. SDK caches the response and uses ETag for conditional requests.

5

Real-time Updates

SSE connection or polling keeps flags in sync. When a flag changes, SDK updates cache and notifies your app.

Real-time Update Mechanisms

Server-Sent Events (SSE)

A persistent HTTP connection that receives flag updates in real-time.

SSE Sequence Diagram
  • + Instant updates (milliseconds)
  • + Single connection, low overhead
  • - May be blocked by some proxies

Polling

Periodic HTTP requests to check for flag updates (default: every 30 seconds).

Polling Sequence Diagram
  • + Works everywhere
  • + Simpler to debug
  • - Slight delay (up to polling interval)

Resilience Patterns

The SDK is designed to keep your application running even when Rollgate is unreachable.

Circuit Breaker

After 5 consecutive failures, the circuit opens and all flag checks use cached values.

Closed (normal)
Open (use cache)
Half-open (testing)

Stale Cache

Even expired cache entries are kept as fallback. Better to serve stale data than fail.

Fresh: Use immediately
Stale: Use + refresh in background
Expired: Use if API fails

Retry with Backoff

Failed requests are retried with exponential backoff (100ms, 200ms, 400ms...).

Attempt 1: immediate
Attempt 2: +100ms
Attempt 3: +200ms (max 3)

Failure Scenarios

ScenarioSDK BehaviorUser Impact
API timeout (single request)Retry up to 3 times, use cacheNone
API down (prolonged)Circuit opens, use cached flagsFlags may be stale
First request fails (cold start)Retry, then use default valuesDefaults until recovered
Network blip during SSEAuto-reconnect with backoffBrief delay in updates

Security Model

Authentication

  • Dashboard: Session-based auth with HTTP-only cookies, OAuth (Google, GitHub)
  • API (management): Session cookie or Bearer token
  • SDK: API key in header (X-API-Key)

API Key Types

  • Client Key (rg_client_*): Read-only, safe for frontend
  • Server Key (rg_server_*): Full ruleset for local evaluation, backend only

RBAC Roles

RolePermissions
OwnerFull access, billing, delete organization
AdminManage flags, members, API keys, projects
MemberCreate/edit flags, view audit logs
ViewerRead-only access to flags and analytics

Analytics Pipeline

Flag evaluation metrics flow from your application to the Rollgate dashboard.

Rollgate Analytics Pipeline

Metrics Collected

  • • Flag evaluation count (per flag, per environment)
  • • True/False distribution (for percentage rollouts)
  • • SDK latency (p50, p95, p99)
  • • Cache hit rate
  • • Circuit breaker state transitions