Free workshop
SEO in 90 minutes: audit your own website. Seats are limited.SEO in 90 minutes: audit your own site.
00d00h00m00s

Zero-downtime deploys for a small team on AWS

You do not need a platform team to ship without downtime. Run two copies, shift traffic in steps and keep the old one ready. Here is a plan a small team can build in a weekend.
Sooraj PFull-stack developer and SEO strategist
5 min read
0 views
Zero-downtime deploys for a small team on AWS
Blue and green server stacks with a lever switching traffic between them, under a cloud with a heartbeat line

Every release is a small risk. A deploy that takes the site down for five minutes costs trust, sales and sleep. Big teams solve this with platform engineers. Small teams can solve it with one simple idea: run two copies and switch between them. This guide shows how to do that on AWS, step by step, with the exact limits from AWS documentation. It also covers the part most guides skip: the database.

01

What zero downtime really means

Zero downtime means users never see an error or a blank page during a release. They keep using the old version until the new one is ready.

AWS describes blue/green deployment as a technique that releases applications “by shifting traffic between two identical environments that are running different versions of the application.”1 The old version is blue. The new one is green.

The big benefit is rollback. AWS says the technique can reduce common deployment risks such as downtime and rollback difficulty.1 If green misbehaves, you send traffic back to blue.

02

In-place or blue/green?

AWS CodeDeploy supports both styles.2 The difference is simple.

Two deployment styles in CodeDeploy
StyleWhat happensTrade-off
In-placeThe app on each instance is stopped, updated and started againCheap, but capacity drops during the update
Blue/greenThe new version is built beside the old one, then traffic is reroutedNeeds spare capacity, but rollback is fast

For blue/green on EC2, CodeDeploy provisions replacement instances and registers them with a load balancer. Then it deregisters the originals. AWS notes that traffic can go back to the original instances as long as you have not terminated them.2

On Amazon ECS and AWS Lambda, traffic can shift in three ways: canary, linear or all at once.2

03

The pipeline in five stages

Keep the pipeline short. Each stage has one job.

  1. 1

    Build

    Create one artifact, such as a container image or a zip, from a tagged commit. Never rebuild for production.

  2. 2

    Test

    Run unit tests and a small set of smoke tests. Fail fast and stop the pipeline.

  3. 3

    Deploy green

    Launch the new version beside the old one. It receives no real traffic yet.

  4. 4

    Verify

    Run a health check and a few real requests against green. Check logs and error rates.

  5. 5

    Shift traffic

    Move users to green in steps, then watch the numbers before you finish.

04

Shifting traffic with ALB weights

An Application Load Balancer can split traffic between target groups by weight. Each weight is a value from 0 to 999, and requests are shared in proportion to the weights.3

AWS gives a clear example. Two groups with weights of 10 and 20 give the second group twice as many requests as the first.3

A simple traffic plan
StepBlue weightGreen weightWhat you watch
Start1000Green passes health checks
Canary9010Error rate and latency
Half5050Error rate, latency and business events
Finish0100Keep blue ready for a rollback window
shift-traffic.json
1{2  "Type": "forward",3  "ForwardConfig": {4    "TargetGroups": [5      { "TargetGroupArn": "<blue-arn>",  "Weight": 90 },6      { "TargetGroupArn": "<green-arn>", "Weight": 10 }7    ]8  }9}
05

Health checks and draining

Two settings protect your users during the switch.

  1. 1

    Health checks

    A new target receives traffic once it is registered and passes its first health check.4 Make the check test something real, such as a database query, not just a static page.

  2. 2

    Deregistration delay

    This sets how long the load balancer waits before it removes a target. The default is 300 seconds and the range is 0 to 3,600.4 Set it a little above your longest normal request.

06

Rollback in one step

A rollback should be boring. If green fails, set its weight to 0 and blue back to 100. Users return to the old version in seconds.

CodeDeploy can also stop and roll back a deployment when it hits errors.2 Use it if you want the tool to decide, and use the manual weight switch if you want a human to decide.

  1. 1

    Write the rollback rule

    Decide in advance which numbers trigger a rollback, such as a 5xx rate above a set limit.

  2. 2

    Keep blue alive

    Do not terminate the old version until the new one has run cleanly for a set time.

  3. 3

    Practise it

    Run a rollback in a quiet hour once. An untested rollback is only a hope.

07

The database is the hard part

Two versions of your app will share one database for a short time. The AWS paper itself flags the data tier as an important consideration.1

So every schema change must work with both the old and the new code. A safe habit is to change the database in two steps.

  1. 1

    Expand

    Add the new column or table. Keep the old ones. Old and new code both work.

  2. 2

    Deploy

    Release the new code. It uses the new structure.

  3. 3

    Contract

    Remove the old column in a later release, after you no longer need to roll back.

08

A weekend plan

This is the order I would build it in. Treat the time as a guide, not a promise.

Two-day build order
WhenTaskDone when
Saturday morningContainerise or package the app and script the buildOne command makes one artifact
Saturday afternoonCreate the blue and green target groups behind one ALBBoth pass health checks
Sunday morningAdd the pipeline stages and the smoke testsA push to main deploys green
Sunday afternoonAdd the weight shift and practise a rollbackYou return to blue in under a minute
09

How I would run it

I would keep the first version plain. No service mesh, no custom controller. One load balancer, two target groups and a script.

I also prefer small releases. Ten small deploys are safer than one big one, because each change is easy to understand and easy to undo.

Cost matters too. Running two copies doubles capacity for a short time. For a small team, that is often cheaper than one hour of downtime.

10

Common mistakes

  • Rebuilding the artifact for production instead of promoting the tested one.

  • Terminating blue before green has run cleanly.

  • Shipping a database change that breaks the old version.

  • Using a health check that only loads a static page.

  • Never practising the rollback.

Quick questions

Do I need containers?

No. Blue/green also works with EC2 instances. Containers make builds more repeatable, but they are not required.

Is blue/green expensive?

You pay for two copies during the release. Keep the window short and scale blue down once the release is safe.

What if my app keeps sessions in memory?

Store sessions in a shared store, or enable stickiness on the rule. Test the behaviour before you shift real traffic.

Can I do this without CodeDeploy?

Yes. ALB weights and a short script are enough. CodeDeploy adds automation and rollback options.

11 · The short version

Key takeaways

  • Run two copies and move traffic between them, so users never see the switch.

  • ALB weights run from 0 to 999 and share requests in proportion.

  • Rollback is a weight change. Keep blue alive until green is proven.

  • Make database changes work with old and new code at the same time.

  • Practise the rollback before you need it.


Join the conversation

Say hello · I reply personally

Tell me how I can help

1 · Details2 · Done

Message received

Thanks, there. I read every message myself and will reply to your inbox within one business day.