---
title: "Implementing Feature Flags from Scratch"
description: "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."
url: "https://swe.quest/articles/implementing-feature-flags-from-scratch-71e3ff66bd030a0e"
canonical: "https://blog.railway.com/p/implement-feature-flags-from-scratch"
source: "Railway"
published: "2024-12-13"
difficulty: "medium"
kind: "How-to"
reading_minutes: 24
tags: ["deployment","javascript","postgres","react"]
---

# Implementing Feature Flags from Scratch

A post on [Railway](https://swe.quest/sources/railway.md), published 2024-12-13, 24 min read, How-to. Original: [https://blog.railway.com/p/implement-feature-flags-from-scratch](https://blog.railway.com/p/implement-feature-flags-from-scratch)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [React](https://swe.quest/tags/react.md) (Web & mobile)

## Prerequisites

- Next.js basics ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- Redis basics ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

Railway, Redis, Next.js, ioredis, PostgreSQL, Railway CLI

## Related posts

- [Roll it out, roll it back, never redeploy](https://swe.quest/articles/roll-it-out-roll-it-back-never-redeploy-c13aa355b1437d78.md): Railway · 2026-07-17 · Medium · 7 min read · Deployment, Configuration management, AI agents, Developer tools
  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.
- [Now you see me, now you don't: feature-flagging with LaunchDarkly at incident.io](https://swe.quest/articles/now-you-see-me-now-you-don-t-feature-flagging-with-launchdarkly-at-incident-io-cb6cda92c3363bee.md): incident.io · 2021-11-09 · Medium · 6 min read · Deployment, Go, React, Testing
  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.
- [How we ship code faster and safer with feature flags](https://swe.quest/articles/how-we-ship-code-faster-and-safer-with-feature-flags-49a97b8efaf60044.md): GitHub Engineering · 2021-04-27 · Medium · 9 min read · Deployment, CI/CD, Testing, Refactoring & migrations, Ruby
  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.
- [A database for every preview environment using Neon, GitHub Actions, and Vercel](https://swe.quest/articles/a-database-for-every-preview-environment-using-neon-github-actions-and-vercel-dd5fe24cba2d12b5.md): Neon · 2023-04-14 · Medium · 14 min read · PostgreSQL, CI/CD, Deployment, Schema migrations
  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.
- [Cal.com launches Expert Marketplace built with Next.js and Supabase.](https://swe.quest/articles/cal-com-launches-expert-marketplace-built-with-next-js-and-supabase-2659e9baa272f3f6.md): Supabase · 2024-06-18 · Medium · 5 min read · PostgreSQL, Frontend, Serverless, Storage systems
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
