A message broker across availability zones

The message broker and the services around it were spread across availability zones in every AWS region, so most messages crossed zones and AWS billed the traffic. The system already had failover between regions, so we kept this traffic inside one zone per region.

$140K saved per year
Change
Broker across zones to One zone per region
Client
Enterprise SaaS company

What we changed

  1. 01Matched the traffic between zones to the broker with the cost report and flow logs
  2. 02Compared the traffic cost with the risk the extra zones covered
  3. 03Broker and its clients in one zone per region
  4. 04Tested failover between regions

The situation

The system ran in several AWS regions. Inside each region the services and the message broker were spread across availability zones, to keep running if a zone went down. Here the broker was NATS, but the same happens with Kafka, RabbitMQ or services that call each other directly.

When a broker cluster has nodes in different zones, a message often goes from one zone to another on its way from the sender to the receivers, and replication copies it to other zones again. Calls between services do the same when the caller and the service it calls are in different zones. AWS charges for traffic between zones in each direction, so the bill grows with every message and every call.

Because the system already had failover between regions, the loss of a zone was already covered. The traffic between zones was paying for protection the system already had.

What we did

1. Found where the traffic came from

We took the data transfer lines from the AWS cost and usage report and matched them to instances with VPC flow logs. Most of the traffic between zones came from the broker and the services around it.

2. Compared cost and risk

For each part of the system we compared the cost of the traffic between zones with the risk the extra zones covered. With failover between regions in place, the risk was already covered.

3. Kept the traffic inside one zone

  • the broker cluster in each region now runs in one zone
  • the services that send and receive messages run in the same zone and connect to the local nodes
  • the links between regions stayed as they were

4. Tested failover

We ran failover between regions to confirm the system still recovers the way it should.

Result

$140k a year saved on AWS. Availability did not change.