Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Railway 24 min read How-to mediumAdept

Implementing Feature Flags from Scratch

Feature flags can be built in-house on a Next.js Twitter clone, using Postgres for app data and Redis for flag state, then deployed to Railway. Three flag types are covered: a random 30% user sample for gradual rollout, stored as a Redis Set and checked with SISMEMBER; manual on/off toggles for things like limited-time drops; and targeting based on user metadata such as IP-derived country. The case for building rather than buying is control, lower latency from keeping the flag store on the same network as the app, and a better grasp of the mechanics before choosing a vendor like LaunchDarkly.

Related posts

  • Roll it out, roll it back, never redeploy

    Railway mediumAdept

    Railway now offers feature flags across its dashboard, CLI, TypeScript SDK and MCP server, so code can ship dark behind a default-off flag and be rolled out to a team, a percentage of users, or targeted segments without redeploying. Percentage rollouts use a stable bucket(key) hash, so raising a threshold never flips users back. Reads evaluate in memory against rulesets fetched at init and refreshed in the background, which makes them cheap enough for hot paths. Instead of rule priorities, conflicting or unmatched rules resolve to the flag's default, and an evaluate API returns a reason and per-rule trace for debugging.

  • Now you see me, now you don't: feature-flagging with LaunchDarkly at incident.io

    incident.io mediumAdept

    incident.io ships to production many times a day and uses feature flags to merge large features like Announcement Rules incrementally while hiding them from customers until launch. The team chose LaunchDarkly over building its own system because feature flagging isn't a differentiator, and integrated it across backend and frontend in a day. On the backend, the Go SDK is wrapped in a featureflags package that centralizes flag names as constants, initializes a singleton client, returns clients scoped to user and organization IDs, and supports injecting mocks so tests cover both flag states. On the frontend, the React SDK hook gates UI, and flags are mostly targeted per organization to run beta tests.

  • How we ship code faster and safer with feature flags

    GitHub Engineering mediumAdept

    GitHub puts risky changes and in-progress features behind feature flags so it can deploy continuously and disable problems in seconds instead of rolling back a deployment over several minutes. Flags can target individual actors (users, orgs, repos, GitHub Apps or custom actor types), all staff, beta groups, a sticky percentage of actors, or a per-request percentage ("dark shipping") for invisible changes such as query optimizations. CI runs two builds, one with all flags on and one with all flags off, to cover both code paths. The costs are runtime lookups (metadata in MySQL cached in memcached, with per-actor MySQL queries for large flags) and dead-code debt, which GitHub is automating away with a git grep and rubocop-ast script that rewrites conditionals and tests and opens a pull request routed to CODEOWNERS.

  • A database for every preview environment using Neon, GitHub Actions, and Vercel

    Neon mediumAdept

    Neon's copy-on-write branching can give every pull request its own production-like Postgres database, avoiding the bottlenecks of shared staging or shared preview databases. Branches are isolated, are created in about a second regardless of database size, and bill only for unique data. A GitHub Actions pipeline creates a Neon branch per PR, runs Prisma migrations against it, deploys a Vercel preview wired to that branch, and comments the URLs on the PR. Merging applies migrations to the primary branch, deploys to production and deletes the preview branch.

  • Cal.com launches Expert Marketplace built with Next.js and Supabase.

    Supabase mediumAdept

    Cal.com's open-source Platform Starter Kit for building expert marketplaces runs on Next.js and Supabase, having switched from SQLite to Postgres via Prisma shortly before launch once file storage was needed. Prisma connects through Supavisor using a pooled transaction-mode URL plus a direct session-mode URL, and its multiSchema feature keeps app tables out of the PostgREST-exposed public schema. Profile images upload to Supabase Storage via server-generated signed upload URLs, which works alongside Auth.js rather than Supabase Auth, and a custom Next.js Image loader serves resized images. A Vercel integration syncs environment variables and can provision a project with migrations and seeds in one click.

The quest for software engineering knowledge.

Look:
Layout: