The problem

Swapping the broker behind a task queue sounds like a connection-string change until you ask the real question: what happens to the job that's mid-flight at the exact moment you cut over? Lose it, and work silently disappears — no error, no log, just a task that never runs. Duplicate it, and you've charged a card twice or sent a notification twice.

The pattern

A four-phase state machine for the cutover: parallel → cutover → draining → decommissioned.

  • Explicit rules for which transitions are allowed, including rollback, at every phase.
  • The old broker only gets decommissioned once two independent signals agree it's actually empty — not one check that could be wrong, not a timer, not an assumption.
  • Terraform provisions the replacement broker (ElastiCache/Valkey): replication group, subnet group, security group, parameter group.

Security findings that came from a real tool, not a self-assessment

This is the project where Checkov stopped being theoretical. Three rounds of real findings, fixed in sequence:

  1. Missing auth_token on the replication group, and multi_az_enabled expressed as a conditional Terraform expression — Checkov's static analysis can't resolve a conditional, it needs a literal true.
  2. Security group and rule missing description, wide-open egress to 0.0.0.0/0 on all ports (removed entirely — the broker never needs to call out), and no customer-managed KMS key on the replication group (added a dedicated aws_kms_key).
  3. The KMS key created in step 2 didn't have an explicit policy — added one scoped to the account root, no wildcard principal.

Each fix revealed the next real finding. The lesson that stuck: only close the loop when CI is actually green, never on the first commit that looks like a fix.

Stack

Python (state machine + 10 tests, all passing locally before push), Terraform/AWS.

Repo: https://github.com/Athilaf/redis-to-elasticache-zero-downtime