‫So let's have a look at some
‫advanced concepts for SQS FIFO.
‫The first one is deduplication.
‫So there is a deduplication interval that is five minutes.
‫And that means that if you send the same message twice
‫within that five minutes,
‫then the second message will be refused.
‫And there are two deduplication methods.
‫The first one is called content-based deduplication.
‫What will happen is as soon as you send a message
‫into SQS there will be a has calculated
‫using the SHA-256 method algorithm of the message body.
‫And if the same message body is encountered twice,
‫the same hash will be the same twice.
‫And so therefore, the second message will be refused.
‫Or you an explicitly provide a message deduplication ID
‫directly while sending a message.
‫And if the same deduplication ID is encountered twice
‫then the message will be gone.
‫So let's have a look.
‫Our SQS FIFO is here.
‫And we produce a hello world message.
‫And say we have enabled content-based deduplication.
‫In that case, the SQS FIFO queue will generate
‫a SHA-256 has of that message.
‫Which may look like something like this in my screen.
‫And so if the producer sends the exact same message
‫it will be hashed to the exact same hash
‫and SQS FIFO will know it.
‫And therefore, the second message will be refused.
‫The second advanced concept we need
‫to look at is message grouping.
‫So the idea is, if you specify the same value
‫for the message group ID in an SQS FIFO queue,
‫which is a mandatory parameter when
‫you send the message to a FIFO queue.
‫Then you will only have one consumer.
‫And all the messages will be in order for that one consumer.
‫But if you just need ordering
‫at the level of a subset of messages,
‫then you should specify different values
‫for message group ID.
‫The idea is that the messages that will share
‫the common message group ID in order within the group.
‫And each group ID will have a different consumer.
‫So you can enable parallel processing
‫on your SQS FIFO queue.
‫But ordering across groups is not guaranteed.
‫So for example, let's say we have a FIFO queue.
‫And we're grouping messages into three groups: A, B, and C.
‫Say we have message A1, A2, A3.
‫Then we can have a consumer for the group A.
‫Then we have another group of messages: B1, B2, B3, B4.
‫We can have another consumer for that group.
‫And another set of message.
‫For example, for consumer group, we have C1 and C2.
‫The idea is that, for example,
‫maybe sometimes you don't need the total ordering
‫of all the messages.
‫But you want ordering of all the messages
‫for a specific customer ID.
‫And for example, for that one specific customer ID,
‫you can use this as your message group ID.
‫And so that means that you can have
‫as many consumers as users you have in your application.
‫And for each user, the messages will be in order,
‫thanks to the guarantee of the SQS FIFO queue.
‫So back into our FIFO queue.
‫Let's edit it, and I'm going
‫to enable content-based deduplication.
‫Where the deduplication ID is going to be computed
‫as a SHA-256 of my messages.
‫So I click on save, and here we go.
‫Now let's go into send and receive messages.
‫And I will send the message hello world.
‫For the message group ID,
‫I will just keep it as demo for now.
‫And for now, as you can see,
‫the message deduplication ID is optional
‫because we have enabled content-based deduplication.
‫So let's send that message.
‫As yo can see, the message is sent and ready to be received.
‫And the message available is one.
‫But if I send again that message,
‫and again, and again, and again,
‫the number of messages available will keep on being one.
‫Because that message has already been seen SQS,
‫and so there is some deduplication happening.
‫But if I send a different message.
‫For example, hello world two.
‫Then a second message will be available
‫right here in SQS FIFO.
‫So as we can see, this is the deduplication happening here.
‫But for example, if I wrote an other message
‫and I used your own deduplication ID.
‫So for example, your own deduplication token.
‫So 1-2-3, and then you send that message again.
‫Thanks to the fact that we specified
‫the same deduplication ID.
‫Then you will only see one of
‫these messages in two SQS FIFO, okay?
‫The other think I want to show you is the group ID.
‫So it's not something that's very easy to show.
‫But the idea is that, for example,
‫if we have a user bought an apple.
‫And the message group ID is user123.
‫And I will just remove this message deduplication ID.
‫And then the user bought a banana.
‫And then the user bought strawberries, right?
‫Because all these messages share
‫the same message group ID.
‫Then they will be in order for that user123.
‫But if I now send a user bought an apple.
‫And an apple that's going to be green, a green apple.
‫And we specify a different message group ID: So user234.
‫Now, these messages for that user234
‫will be in order for that user.
‫And so now, in my SQS FIFO queue,
‫I can have multiple consumers running at the same time.
‫And each of the consumers will be consuming
‫from a different message group ID, okay?
‫So that's it.
‫Now when you're done, you can just
‫pull the messages and have a look.
‫But I will go ahead and just simply delete them.
‫So that's it, I hope you liked it
‫and I will see you in the next lecture.