惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
A
Arctic Wolf
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
A
About on SuperTechFans
P
Palo Alto Networks Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
D
DataBreaches.Net
Cyberwarzone
Cyberwarzone
T
Tor Project blog
IT之家
IT之家
P
Proofpoint News Feed
Help Net Security
Help Net Security
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
Microsoft Azure Blog
Microsoft Azure Blog
V2EX - 技术
V2EX - 技术
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
B
Blog
N
News and Events Feed by Topic
The Cloudflare Blog
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LangChain Blog
I
InfoQ
F
Full Disclosure
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
H
Hacker News: Front Page
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Deploy Your Apps with 0 downtime Part 1 (Blue-Green Deployment)
satriaherman · 2026-05-21 · via DEV Community

Overview

Have you ever experienced your app can't be accessed whenever you release a new version of your app?. In this series, we'll explore how to deploy updates with zero downtime, starting with one of the most reliable strategies — Blue-Green Deployment.

When we deploy an application on Cloud provider like AWS, Azure or GCP, we usually do like this:

  • Shutting down the app
  • compiled new version code
  • Start app again

Looks like there's no problem with steps above until we noticed that our app is getting down or can't be accessed during the deployment process. we call this situation as downtime.

In this article we will learn how to prevent that using a one of deployment strategies called Blue-Green Deployment.

What it is Blue-Green Deployment?

Blue-Green Deployment is a strategy which we will switch the traffic from previous version instances(blue) to another identical new release instances(green) which are running on production environment. To achieve this goal, load balancer is playing crucial function to switching traffic

In this tutorial, we will use docker as a container manager and nginx as load balancer. We will deploy nextjs app and simulate it to achieve 0 downtime by using blue green deployment

Before we started, make sure you already install software bellow:

Notes: make sure you are familiar with linux environment

Install Docker and Nginx

open wsl and type bellow to install nginx

sudo apt install nginx

Enter fullscreen mode Exit fullscreen mode

after nginx installed we will install docker,nodejs and git

sudo apt install docker nodejs git

Enter fullscreen mode Exit fullscreen mode

after you installed the tools above, please create directory following image bellow

Setup Docker

We will use docker compose to run the app and nginx inside the container. so on Dockerfile, write this code

FROM node:20-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

EXPOSE 3000

CMD ["npm", "start"]

Enter fullscreen mode Exit fullscreen mode

Before Implement Blue Green Deployment

Before we start to setup the blue green deployment. i will show you the deployment before implement Blue Green deployment. i will write the docker-compose.yml like this.

services:
  app:
    build: ./app
    container_name: app
    ports:
      - "5001:3000"


  nginx:
    image: nginx:latest
    container_name: nginx-bluegreen
    ports:
      - "80:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/active_backend.conf:/etc/nginx/conf.d/active_backend.conf

Enter fullscreen mode Exit fullscreen mode

and for nginx.conf

events {}

http {



    server {
        listen 80;

        location / {
            proxy_pass http://host.docker.internal:5001;

            proxy_http_version 1.1;

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

            proxy_set_header Host $host;
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

and then i will write the deployment script on deploy.sh

#!/bin/bash

set -e

echo "================================="
echo "Starting Deployment..."
echo "================================="

echo ""
echo "[1/5] Building container..."

docker compose build app

echo ""
echo "[2/5] Stopping old container..."

docker compose stop app

echo ""
echo "[3/5] Removing old container..."

docker compose rm -f app

echo ""
echo "[4/5] Starting new container..."

docker compose up -d --no-deps app

echo ""
echo "[5/5] Running health check..."

sleep 5

STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost/api/health-check)

if [ "$STATUS" != "200" ]; then
    echo "Deployment failed!"
    exit 1
fi

echo ""
echo "================================="
echo "Deployment Success!"
echo "================================="

Enter fullscreen mode Exit fullscreen mode

the i will running the container using docker compose

docker compose up

Enter fullscreen mode Exit fullscreen mode

and now when i visit http://localhost the page will showing

now i will run ./deploy.sh to simulate the deployment process. when i refresh the page many times, i got the 502 bad gateway we called this as downtime

the downtime occur because i need to stop the container while i building new image version. so, the page will unavailable for some time. to prevent the downtime we need to create 2 app, one for active app and one for standby app. so when new release detected, we will rebuild the standby app, do the healthy check to make sure the app is healthy, then when app is detected as healthy app, we switch the traffic to new release app. here's the ilustration

Implement Blue Green

To Implement the Blue Green deployment, we will change our deployment mechanism like this:

  • deploy 2 services called app_blue and app_green
  • configure the nginx to route the traffic to app_blue
  • write the current active app to "blue"
  • new deployment detected
  • rebuild app_green
  • do health check the app_green
  • if healthy switch traffic to app_green
  • write the current active app to "green"

Create Healthy Check Route

Inside the nextjs app, we will create a route to indicates that the application is running well and healthy

open app/api/health-check/route.ts and write the code below:

export async function GET() {
  return Response.json({
    ok: true
  })
}

Enter fullscreen mode Exit fullscreen mode

run your app

npm run dev

Enter fullscreen mode Exit fullscreen mode

then test the script by running

curl http://localhost:3000/api/health

Enter fullscreen mode Exit fullscreen mode

it should return

{"ok":true}

Enter fullscreen mode Exit fullscreen mode

after that, we will setup the docker compose to running 2 nextjs app and nginx as load balancer.

services:
  app_blue:
    build: ./app
    container_name: app-blue
    ports:
      - "5001:3000"

  app_green:
    build: ./app
    container_name: app-green
    ports:
      - "5002:3000"

  nginx:
    image: nginx:latest
    container_name: nginx-bluegreen
    ports:
      - "80:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/active_backend.conf:/etc/nginx/conf.d/active_backend.conf

Enter fullscreen mode Exit fullscreen mode

on code above, we created 2 services for apps that running on port 5001and 5002. and we created nginx services as a load balancer that will switch the traffic everytime when the new deployment found.

Setup Nginx

open nginx folder on the root folder and create nginx.conf

events {}

http {

    include /etc/nginx/conf.d/active_backend.conf;

    server {
        listen 80;

        location / {
            proxy_pass http://active_backend;

            proxy_http_version 1.1;

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

            proxy_set_header Host $host;
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

In nginx.conf, we forward all requests to the active backend defined in active_backend.conf, which is imported from the nginx folder.

on active_backend.conf we will write this configuration file

upstream active_backend {
    server host.docker.internal:5001;
}

Enter fullscreen mode Exit fullscreen mode

on active_backend.conf we created the upstream named active_backend. the active_backend is route all request to localhost:5001 that running under the docker container. so we must define host.docker.internal:5001

Store Current Active App

To store current active app. we will create new file called active_slot which is contain txt content

green

Enter fullscreen mode Exit fullscreen mode

Deployment Script

We will create file deploy.sh to simulate our deployment script including :

  • check the active app
  • rebuild the standby app
  • hit the health check of new release app
  • switching the traffic to new release app
#!/bin/bash

set -e

ACTIVE=$(cat active_slot)

if [ "$ACTIVE" = "blue" ]; then
    TARGET="green"
    TARGET_PORT=5002
    TARGET_SERVICE="app_green"
else
    TARGET="blue"
    TARGET_PORT=5001
    TARGET_SERVICE="app_blue"
fi

echo "============================"
echo "Current Active : $ACTIVE"
echo "Deploy Target  : $TARGET"
echo "============================"

echo ""
echo "[1/5] Rebuilding $TARGET_SERVICE..."

docker compose build $TARGET_SERVICE
docker compose up -d --no-deps $TARGET_SERVICE

echo ""
echo "[2/5] Waiting app startup..."

sleep 10

echo ""
echo "[3/5] Running health check..."

for i in {1..20}
do
    STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TARGET_PORT/api/health-check)

    if [ "$STATUS" = "200" ]; then
        echo "Health check success!"
        break
    fi

    echo "Retry $i..."
    sleep 3
done

if [ "$STATUS" != "200" ]; then
    echo "Health check failed!"
    exit 1
fi

echo ""
echo "[4/5] Switching nginx traffic..."

cat > nginx/active_backend.conf <<EOF
upstream active_backend {
    server host.docker.internal:$TARGET_PORT;
}
EOF

docker exec nginx-bluegreen nginx -s reload

echo "$TARGET" > active_slot

echo ""
echo "[5/5] Deployment success!"
echo ""
echo "Active slot now: $TARGET"

Enter fullscreen mode Exit fullscreen mode

look at

docker compose build $TARGET_SERVICE
docker compose up -d --no-deps $TARGET_SERVICE

Enter fullscreen mode Exit fullscreen mode

because we are running 2 services from same image we need to add

--no-deps

Enter fullscreen mode Exit fullscreen mode

options to prevent the docker restart the active app while it rebuild the image. so the active app can still running.

edit page.tsx and run the deploy.sh. now the downtime is gone while we deploy new version in our app