SQS Flashcards
two patterns of application communication
synchronous and asynchronous communication
synchronous communication
your application will be directly connecting to another application of yours.
buying service –> shipping service
when something is bought, we need to talk to the shipping service to send that item that was just bought.
asynchronous communication
or event based.
There will be a middleware called a queue that will connect your applications.
So this time the buying service says, hey, someone bought something, and so I’m gonna put that into a queue, and that’s it. And the shipping service says, hey queue, is there something that got bought recently? And the queue will return that element
and the shipping service can do whatever it wants.
So the buying service and the shipping service are not directly connected.
buying service –> queue –> shipping service
synchronous between applications can be a little bit problematic sometimes,
if one service overwhelms the other because there is a sudden spike of purchases or whatever,
for example we have a video encoding service, and we need to encode 1,000 videos but usually it’s 10.
Well, our encoding service is going to be overwhelmed and we’re going to have outages.
So, when you have these sudden spikes of traffic or you can’t predict anything, then it’s usually better to decouple your application and have the decoupling layer scale for you.
decoupling layer
SQS for a queue model,
SNS for a pub/sub model,
Kinesis, if you do real time streaming and you have like big data.
SQS
a queuing service
a buffer to decouple between your producers and your consumers, to decouple applications
producer
whatever sends a message into our SQS queue
can be one or more
consumers
something needs to process the messages from the queue and receive them
consumers will poll the messages from the queue
you may have multiple consumers consuming messages from an SQS queue
throughputs
you can send as many messages per second as you want, and the queue can have as many messages as you want as well.
So there’s no limit on throughputs and no limits in the number of messages in the queue.
by default, the message will stay in the queue
for four days and the maximum amount of time
that a message can be in a queue is 14 days.
as soon as you send a message to a queue, it has to be read by consumer and deleted from the queue
after being processed within that retention period,
otherwise, it will be lost.
low-latency
whenever you send a message or read a message from SQS, you will get a response very quickly, less than 10 milliseconds on publish and receive.
message size
messages in SQS have to be small. They have to be less than 256 kilobytes per messages sent.
duplication
it is possible to have duplicated messages
In rare occasions, the retry mechanism might cause duplicate notifications for the same object event.
this is true for Standard SQS, and you have to take this into account in your application
the problem is solved in FIFO SQS and there is also message deduplication solution
message order
for standard SQS: It can have out of the order messages, which means it’s best effort ordering,
there is another type of offering from SQS that can deal with that limitation,
the producers will send the messages to SQS using
an SDK, software development kits. And the API to send a message to SQS is called SendMessage.