Message all instances behind load balancer

Viewed 151

I need to notify all machines behind a load balancer when something happens.

For example, I have machines behind a load balancer which cache data, and if the data changes I want to notify the machines so they can dump their caches.

I feel as if I'm missing something as it seems I might be overcomplicating how I talk to all the machines behind my load balancer.

--

Options I've considered

SNS

The problem with this is such that each individual machine would need to be publicly accessible over HTTPS.

SNS Straight to Machines

Machines would subscribe themselves with their EC2 URL with SNS on startup. To achieve this I'd need to either

  1. open those machines up to http from anywhere (not just the load balancer)
  2. create a security group which lets SNS IP ranges into the machines over HTTPS.
    • This security group could be static (IPs don't appear to have changed since ~2014 from what i can gather)
    • I could create a scheduled lambda which updates this security group from the json file provided by AWS if I wanted to ensure this list was always up to date.

SNS via LB with fanout

The load balancer URL would be subscribed to SNS. When a notification is received one of the machines would receive it.

The machine would use the AWS API to look at the autoscaling group it belongs to to find other machines attached to the same load balancer and then send the other machines the same message using its internal URL.

SQS with fanout

Each machine would be a queue worker, one would receive the message and forward on to the other machines in the same way as the SNS fanout described above.

Redis PubSub

I could set up a Redis cluster which each node subscribes to and receives the updates. This seems a costly option given the task at hand (especially given I'm operating in many regions and AZs).

Websocket MQTT Topics

Each node would subscribe to an MQTT topic and received the update this way. Not every region I use supports IOT Core yet so I'd need to either host my own broker in each region or have every region connect to their nearest supported (or even a single) region. Not sure about the stability of this but seems like it might be a good option perhaps.

I suppose a 3rd party websocket service like Pusher or something could be used for this purpose.

Polling for updates

Each node contains x cached items, I would have to poll for each item individually or build some means by which to determine which items have changed into a bulk request.

This seems excessive though - hypothetically 50 items, at polling intervals of 10 seconds

6 requests per item per minute 6 * 50 * 60 * 24 = 432000 requests per day to some web service/lambda etc. Just seems a bad option for this use case when most of those requests will say nothing has changed. A push/subscription model seems better than a pull/get model.

I could also use long polling perhaps?

Dynamodb streams

The change which would cause a cache clear is made in a global DynamoDB table (not owned by or known by this service) so I could perhaps allow access to read the stream from that table in every region and listen for changes via that route. That couples the two services pretty tightly though which I'm not keen on.

0 Answers
Related