Azure Service Bus: binaries to Blob Storage, IDs on the bus

Services sent binary files through Azure Service Bus. Now binaries go to Azure Blob Storage, metadata to SQL Server, and the bus carries only IDs. The client saves more than $100k a month.

$100K+ saved per month
Saved per year
$1.2M+
Change
Binaries on the bus to IDs only
Client
Enterprise SaaS company

What we changed

  1. 01Measured message count and size per queue and topic
  2. 02Binaries to Azure Blob Storage, metadata to SQL Server
  3. 03Only IDs on the bus, consumers read by ID (claim check)
  4. 04Rolled out one message type at a time
  5. 05Removed unused queues, scaled the namespace down

The situation

Services exchanged data through Azure Service Bus, and many messages carried binary files. Large messages are the most expensive kind of traffic on Service Bus: they take more capacity, more network and more time to process. Each binary could cross the bus and the network several times on its way between services, and the bill grew with the traffic.

What we did

1. Measured the traffic

We measured message count and size for every queue and topic. Most of the bill came from a small number of message types that carried binaries.

2. Binaries to Blob Storage, metadata to SQL Server

We changed where the data goes:

  • the binary is written to Azure Blob Storage
  • its metadata is written to SQL Server
  • the message on the bus carries only the ID

This is the claim check pattern: the data stays in storage, and the message only says where to find it.

3. Consumers read by ID

Consumers take the ID from the message and read the metadata from SQL Server and the binary from Blob Storage, only when they actually need it. Handlers are idempotent, so a message delivered twice does no harm.

4. No lost messages

The metadata and the event are written in the same database transaction, and the event is published after that. If a service fails between the two steps, the message is not lost.

5. Rolled out one message type at a time

Old and new formats ran side by side for each message type until the consumers had switched. Then the old format was removed.

6. Cleaned up

We removed queues and subscriptions nobody used any more and scaled the Service Bus namespace down to the new volume.

Result

More than $100k a month saved. The application works the same way, and there is much less network traffic.