Table of Contents

Microservices + UI: CI/CD Pipeline Architecture

GitHub + GitLab + Docker + Nginx Blue-Green Deployment

1. Overview

This document describes the CI/CD architecture for a microservices platform where:

This approach is commonly used to reduce pipeline time and infrastructure cost.

*Note

The services name used in this document are dummy service names. Since the document is generic and similar approach can be adapted for other CICD deployments irrespective of inclusion/exclusion of Microservices from the application architecture.

2. High Level Architecture

SystemPurpose
GitHubSource code repository
GitLab CIBuild & deployment pipelines
DockerContainerization
GitLab RegistryDocker image storage
Docker ComposeService orchestration
NginxTraffic routing
Linux ServersRuntime environments

3. CI/CD Pipeline Flow

4. Deployment Approval Workflow

The pipeline includes manual approval gates to ensure controlled deployments.

EnvironmentApproval RequiredDescription
DEVCode ReviewCode merged after peer review
TESTTest ManagerQA validation before testing
PRODUAT + Release ManagerBusiness validation before production

5. Dynamic Microservice Pipeline

Large systems may contain 20–100 microservices.

Instead of rebuilding everything, the pipeline:

  1. Detects changed services
  2. Generates jobs dynamically
  3. Builds only those services

Example

If only:

auth-service
booking-service

changed, then pipeline creates jobs:

build-auth-service
deploy-auth-service

build-booking-service
deploy-booking-service

Other services are skipped.

This reduces pipeline time drastically.

6. Docker Image Lifecycle

Each microservice is containerized and pushed to:

GitLab Container Registry

Image Retention Policy

To reduce storage cost:

Keep latest 5 images  Delete older images automatically

Example:

auth-service
├── v1
├── v2
├── v3
├── v4
└── v5

Older images are removed automatically.

7. Blue-Green Production Deployment

Production environment contains two identical environments.

EnvironmentRole
BlueCurrently active
GreenNew deployment

Deployment Process

  1. Blue is currently serving traffic
  2. New version deploys to Green
  3. Health checks run
  4. Nginx switches traffic
  5. Blue becomes standby

8. Nginx Traffic Switching

Nginx acts as the traffic router.

Example Nginx upstream

upstream backend {
  server green:8080;
}

Switching traffic:

nginx -s reload

Result:

Zero downtime release

9. Health Check & Rollback

After deployment:

/health  /ready  /status

are validated.

If healthy

Switch traffic to Green

If unhealthy

Rollback to Blue

Users never experience downtime.

10. Selective Service Restart

Instead of restarting the entire stack:

docker compose up -d auth-service

Only updated services restart.

Benefits:

11. Logging Strategy

Each service maintains separate log directories.

Example:

logs/
  auth-service/
    auth-service-v1.log
    auth-service-v2.log
  booking-service/
    booking-service-v3.log

Benefits:

12. Repository Directory Structure

Adapted project structure:

platform-root/

services/
│
├── auth-service/
│
├── src
│
├── Dockerfile
│
└── service.yml
│
├── booking-service/
│
├── src
│
├── Dockerfile
│
└── service.yml
│
└── payment-service/

docker/
  docker-compose.dev.yml
  docker-compose.test.yml
  docker-compose.blue.yml
  docker-compose.green.yml

nginx/
  nginx.conf
  upstream.conf

logs/
  auth-service/
  booking-service/
  payment-service/

scripts/
  detect-changed-services.sh
  generate-dynamic-pipeline.sh
  deploy-service.sh
  nginx-switch.sh
  cleanup-old-images.sh

.gitlab-ci.yml
README.md

13. Benefits of This Architecture

Faster Pipelines

Only changed services build.

Lower Infrastructure Cost

Old images automatically removed.

Zero Downtime Deployments

Blue-Green strategy with Nginx.

Production Safety

Approval gates prevent accidental releases.

Better Observability

Per-service logging.

Enterprise Scalability

Supports 50+ microservices easily.

14. Typical Deployment Timeline

StageTime
Code build2–5 min
Docker image build2 min
DEV deployment1 min
TEST deployment2 min
Production blue-green30 sec

Typical full release:

~10 minutes