zlacker

[return to "On SQS"]
1. mabbo+kK[view] [source] 2019-05-27 15:21:27
>>mpweih+(OP)
A long time ago, as new-ish developer, I was building a system that needed to take inputs, then run "pass/fail/wait and try again later" until timeout or completion. This wasn't mission-critical stuff, mind you, so a lost message would annoy someone but not cause any actual harm.

As I was figuring out how to setup a datastore, query it for running workflows and all that jazz, I happened upon an interesting SQS feature: Post with Delay.

And so, the system has no database. Instead, when new work arrives it posts the details of the work to be done to SQS. All hosts in the fleet are polling SQS for messages. When they receive one, they do the checks and if the process isn't complete they repost the message again with a 5-minute delay. In 5 minutes, a host in the fleet will receive the message and try again. The process continues as long as it needs to.

Looking back, part of me now is horrified at this design. But: that system now has thousands of users and continues to scale really well. Data loss is very rare. Costs are low. No datastore to manage. SQS is just really darned neat because it can do things like that.

◧◩
2. Rapzid+gm1[view] [source] 2019-05-27 20:38:35
>>mabbo+kK
The biggest gotcha in a design like this IMHO is that you can't post and delete atomically. You may post the new work into the queue and then a failure to delete could occur and the work will stack.

Depending on the workload this could be not a big deal or very expensive. Treating a queue as a database, particularly queues that can't participate in XA transactions, can get you in trouble quick.

◧◩◪
3. kondro+Hq2[view] [source] 2019-05-28 12:03:21
>>Rapzid+gm1
But you could adjust the message visibility timeout of the message you received so that it appears back later in the queue itself.
◧◩◪◨
4. Rapzid+Z93[view] [source] 2019-05-28 17:02:47
>>kondro+Hq2
For this specific use case, as described, this sounds like a possible very good approach.
◧◩◪◨⬒
5. kondro+JM3[view] [source] 2019-05-28 21:08:23
>>Rapzid+Z93
One thing to be aware of for this approach though is that you can only have 120k in-flight messages per queue.
[go to top]