Reputation: 816
I was wondering how would an efficient implementation of the SQS visibility timeout looks like. Are the messages put in another queue and a worker sweeps over it and removes those that reached the timeout threshold?
Upvotes: 0
Views: 508
Reputation: 269081
I would personally implement it by storing a timestamp
that says when to make it visible.
ReceiveMessage()
, do not return any messages where timestamp < now
timestamp < now
messages as In Flighttimestamp >= now
, do nothing!While there would be a lot of timestamp comparisons, this would be no worse than checking a status code. Plus, there's no need to clear the timestamp when the time has past, so it is "efficient" in that no 'sweep' processes are required.
Amazon SQS is highly distributed across multiple servers and multiple Availability Zones, so it is most efficient to avoid any possible data update since it would need to be replicated amongst servers.
Upvotes: 1