I'm implementing my service on AWS as a set of stateless EC2 nodes controlled by an ASG, backed by an RDS instance. I need to throttle the overall number of outgoing messages my service sends but can't throttle the number of incoming messages.
The specific outgoing messages in this case are SES messages, but the problem seems pretty general to me (my service sends transactional mail, this is not a bulk-mailing problem).
"Use Guava RateLimiter" is not a sufficient solution, the number of instances in my ASG needs to remain variable but the overall number of messages sent across the group of nodes needs to remain under the limit. I think there's going to have to be some shared-state here.
I'm thinking I'm going to have to implement some kind of queue of work items in the database and then some kind of slot-based throttling system to limit the amount of outgoing messages each node processes, so that the overall number of outgoing messages doesn't exceed my limit.
My solution doesn't need to be internet-scale, but I'd like it to be able to deal with a few-thousand outgoing messages per-second. I'm pretty sure the above-mentioned queue/slot-processor system will easily stretch that far on an RDS instance (and it can be re-factored later to work off of Elasticache or something). Another thing I like about the proposed system above is its minimum initial cost at low-scale (well, discounting my cost to write the code).
Are there any AWS services, SaaS solutions or even just libraries that can help me with this? I'm thinking cost-wise, a full-fledged AWS / SaaS solutions will have a cheap introductory tier initially, and as long as the price doesn't get crazy to scale up it should be fine.