<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>queues Archives - PythonRight</title>
	<atom:link href="https://pythonright.com/tag/queues/feed/" rel="self" type="application/rss+xml" />
	<link>https://pythonright.com/tag/queues/</link>
	<description>Clean code is written by those who care.</description>
	<lastBuildDate>Thu, 08 Sep 2022 16:46:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.2</generator>

<image>
	<url>https://pythonright.com/wp-content/uploads/2018/11/python-right-logo-150x150.png</url>
	<title>queues Archives - PythonRight</title>
	<link>https://pythonright.com/tag/queues/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SQS— Introduction to FIFO Queues</title>
		<link>https://pythonright.com/sqs-introduction-to-fifo-queues/</link>
					<comments>https://pythonright.com/sqs-introduction-to-fifo-queues/#respond</comments>
		
		<dc:creator><![CDATA[Julian Camilleri]]></dc:creator>
		<pubDate>Thu, 08 Sep 2022 16:46:23 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[queues]]></category>
		<guid isPermaLink="false">https://pythonright.com/?p=255</guid>

					<description><![CDATA[<p>Simple Queue Service offers an easy interface to make use of message queueing — where you can store messages to be later processed by your logic, commonly used with microservices or distributed systems (a system that is spread across multiple nodes/computers). What’s a first-in-first-out queue?A first-in-first-out queue is somewhat equivalent to a queue at a shop — the first &#8230; <a href="https://pythonright.com/sqs-introduction-to-fifo-queues/" class="more-link">Continue reading <span class="screen-reader-text">SQS— Introduction to FIFO Queues</span></a></p>
<p>The post <a rel="nofollow" href="https://pythonright.com/sqs-introduction-to-fifo-queues/">SQS— Introduction to FIFO Queues</a> appeared first on <a rel="nofollow" href="https://pythonright.com">PythonRight</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<section data-field="body" class="e-content">
<section name="7352" class="section section--body section--first"><div class="section-divider"><hr class="section-divider"></div><div class="section-content"><div class="section-inner sectionLayout--insetColumn"><p name="4408" id="4408" class="graf graf--p graf-after--h3"><strong class="markup--strong markup--p-strong">S</strong>imple <strong class="markup--strong markup--p-strong">Q</strong>ueue <strong class="markup--strong markup--p-strong">S</strong>ervice offers an easy interface to make use of message queueing — where you can store messages to be later processed by your logic, commonly used with microservices or distributed systems (a system that is spread across multiple nodes/computers).</p><p name="c2d3" id="c2d3" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">What’s a first-in-first-out queue?</strong><br>A first-in-first-out queue is somewhat equivalent to a queue at a shop — the first message that makes it to the queue is the first message that is pushed to the consumer, as shown in the example below.</p><figure name="1b83" id="1b83" class="graf graf--figure graf-after--p graf--trailing"><img decoding="async" class="graf-image" data-image-id="1*oW8OUj7vbSZgOQyP1LjY_Q.png" data-width="596" data-height="231" src="https://cdn-images-1.medium.com/max/800/1*oW8OUj7vbSZgOQyP1LjY_Q.png"></figure></div></div></section><section name="49b4" class="section section--body"><div class="section-divider"><hr class="section-divider"></div><div class="section-content"><div class="section-inner sectionLayout--insetColumn"><p name="e6eb" id="e6eb" class="graf graf--p graf--leading">The most important attribute that we’ll focus on in this article is the <code class="markup--code markup--p-code">MessageGroupId</code> required attribute, the attribute is the backbone of how <code class="markup--code markup--p-code">fifo</code> queues handle ordering in AWS.</p><p name="beed" id="beed" class="graf graf--p graf-after--p">It’s used to communicate to the queue on which ‘partition’ you’d like to enqueue the message, as shown below:</p><figure name="5790" id="5790" class="graf graf--figure graf-after--p"><img decoding="async" class="graf-image" data-image-id="1*vlevTKTy4zTR7s6CYt0yFA.png" data-width="621" data-height="624" src="https://cdn-images-1.medium.com/max/800/1*vlevTKTy4zTR7s6CYt0yFA.png"></figure><br><p name="b56a" id="b56a" class="graf graf--p graf-after--figure">The order of messages is maintained within every message group (partition), not across multiple message groups — meaning that if you have multiple users carrying out actions, ideally you want the message group to be something on the lines of <code class="markup--code markup--p-code">user_&lt;user_id&gt;</code> so actions from a particular user are grouped and processed in the order they happen.</p><p name="9aea" id="9aea" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">How can I have multiple consumers reading from the same queue?<br></strong>In the example below, we’ll go over how AWS handles maintaining the order of messages whilst having multiple consumers reading from the same queue.</p><figure name="50e6" id="50e6" class="graf graf--figure graf-after--p"><img decoding="async" class="graf-image" data-image-id="1*XFzr-UZyiOizR4Q0OYm2Nw.png" data-width="610" data-height="332" data-is-featured="true" src="https://cdn-images-1.medium.com/max/800/1*XFzr-UZyiOizR4Q0OYm2Nw.png"></figure><br><p name="40ca" id="40ca" class="graf graf--p graf-after--figure">Taking a look at the diagram above, we’re seeing:</p><ul class="postList"><li name="beee" id="beee" class="graf graf--li graf-after--p">Groups of customers — equivalent to messages grouped by a <code class="markup--code markup--li-code">MessageGroupId</code> (Group 1, Group 2, Group 3)</li><li name="46d9" id="46d9" class="graf graf--li graf-after--li">Shop — equivalent to a <code class="markup--code markup--li-code">fifo</code> queue</li><li name="0663" id="0663" class="graf graf--li graf-after--li">Multiple employees — equivalent to multiple consumers reading from the same queue (commonly referred to as <code class="markup--code markup--li-code">competing consumers</code>)</li></ul><p name="c97c" id="c97c" class="graf graf--p graf-after--li"><strong class="markup--strong markup--p-strong">Scenario 1<br>We only have messages in Group 1<br></strong>The first message from Group 1 is picked up by one of the consumers and that message group is <strong class="markup--strong markup--p-strong">locked</strong> (other messages can’t be sent out to the consumers) until that first message is acknowledged.</p><p name="15c4" id="15c4" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">Scenario 2<br>We have messages in all message groups<br></strong>The consumers will pick messages from any message group but the order within every message group is maintained through the locking mechanism described in <strong class="markup--strong markup--p-strong">Scenario 1</strong>; this is where one needs to pay close attention as to how the messages are grouped in order to promote interleaving.</p><p name="fe11" id="fe11" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">Scenario 3<br>We have an issue with processing a message from Group 1<br></strong>The unacknowledged message blocks the entire message group, until the message is handled either through the visibility timeout expiring and the message re-sent, or the max retries is reached and the message is sent to the dead-letter queue.</p><p name="c46f" id="c46f" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">How can I promote interleaving?<br></strong>It all depends on the data model; although if we take a simple example of a data structure:</p><figure name="8c98" id="8c98" class="graf graf--figure graf-after--p"><img decoding="async" class="graf-image" data-image-id="1*-8zajE4HnaQazPwOrm2aEw.png" data-width="541" data-height="275" src="https://cdn-images-1.medium.com/max/800/1*-8zajE4HnaQazPwOrm2aEw.png"></figure><br><p name="a9fd" id="a9fd" class="graf graf--p graf-after--figure">Making the assumption that we care about the order of events on the vehicles we can take two routes:</p><p name="e5a9" id="e5a9" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">Grouping by dealer group <br></strong>This would mean that a dealer group can only have one consumer at a time — since a message group locks to maintain order as explained in <strong class="markup--strong markup--p-strong">Scenario 1</strong>.</p><p name="a095" id="a095" class="graf graf--p graf-after--p">This would result in a backlog of events and poor performance.</p><p name="9d00" id="9d00" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">Grouping by dealer<br></strong>This would mean that every dealer can have its own consumer, which would lead to better performance.</p><p name="1ec8" id="1ec8" class="graf graf--p graf-after--p graf--trailing">One can try and go lower in the data structure to gain better performance — but in a nutshell, the less contagious your data is, the more likely you are to have a great outcome in terms of performance (better processing)</p></div></div></section><section name="b271" class="section section--body section--last"><div class="section-divider"><hr class="section-divider"></div><div class="section-content"><div class="section-inner sectionLayout--insetColumn"><p name="ccdb" id="ccdb" class="graf graf--p graf--leading"><strong class="markup--strong markup--p-strong">Configuration Overview</strong></p><figure name="7e76" id="7e76" class="graf graf--figure graf-after--p"><img decoding="async" class="graf-image" data-image-id="1*6VH-BMfwc1iXh_kFgpvrNA.png" data-width="2526" data-height="906" src="https://cdn-images-1.medium.com/max/800/1*6VH-BMfwc1iXh_kFgpvrNA.png"></figure><br><p name="1f4f" id="1f4f" class="graf graf--p graf-after--figure"><strong class="markup--strong markup--p-strong">What’s visibility timeout used for?<br></strong>The amount of time you want SQS to wait before re-sending the same (unacknowledged) message.</p><p name="f7ab" id="f7ab" class="graf graf--p graf-after--p">I would recommend that you profile (calculate) how long it takes for your logic to process a single message, and add reasonable padding — which would guarantee that SQS won’t send out the same message whilst you’re still processing it.</p><p name="fe82" id="fe82" class="graf graf--p graf-after--p">A more robust solution would be to have a ‘heartbeat’ — where you extend the visibility timeout of a message whilst processing. (Examples: <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs-example-visibility-timeout.html#change-the-visibility-timeout" data-href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs-example-visibility-timeout.html#change-the-visibility-timeout" class="markup--anchor markup--p-anchor" rel="noopener noreferrer" target="_blank">Python</a> / <a href="https://github.com/bbc/sqs-consumer#api" data-href="https://github.com/bbc/sqs-consumer#api" class="markup--anchor markup--p-anchor" rel="noopener noreferrer" target="_blank">JavaScript</a>)</p><p name="2571" id="2571" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">What’s the delivery delay setting used for?<br></strong>The amount of time you want SQS to wait before making a new message available.</p><p name="954f" id="954f" class="graf graf--p graf-after--p">A delay of five seconds would mean that once you add a message to a queue, that particular message cannot be retrieved by any of your consumers until that delay has expired.</p><p name="13dc" id="13dc" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">What’s the receive message wait time used for?</strong></p><ul class="postList"><li name="f9c4" id="f9c4" class="graf graf--li graf-after--p">Receive message wait time is set to 0<br>A request is sent to the servers and a query is executed; a response is returned to the client (with or without results) — referred to as <code class="markup--code markup--li-code">short polling</code> .</li><li name="0be5" id="0be5" class="graf graf--li graf-after--li">Receive message wait time is set to larger than 0<br>A request is sent to the servers and the server looks for results for the specified amount of time, once the time expires the results (if any) are returned — referred to as <code class="markup--code markup--li-code">long polling</code>.</li></ul><p name="6261" id="6261" class="graf graf--p graf-after--li"><strong class="markup--strong markup--p-strong">What’s the message retention period used for?<br></strong>The amount of time you want SQS to retain messages for — any messages older than the time specified will be deleted.</p><p name="823a" id="823a" class="graf graf--p graf-after--p"><strong class="markup--strong markup--p-strong">What’s a dead-letter queue?</strong></p><figure name="d3c6" id="d3c6" class="graf graf--figure graf-after--p"><img decoding="async" class="graf-image" data-image-id="1*cFsgSzOEiaLJ7bIbgbKGEA.png" data-width="2150" data-height="754" src="https://cdn-images-1.medium.com/max/800/1*cFsgSzOEiaLJ7bIbgbKGEA.png"></figure><br><p name="d6db" id="d6db" class="graf graf--p graf-after--figure">A dead-letter queue refers to a queue that is used to store messages that are not acknowledged or processed successfully.</p><p name="c042" id="c042" class="graf graf--p graf-after--p graf--trailing"><strong class="markup--strong markup--p-strong">How are messages acknowledged?<br></strong>A received message is not automatically acknowledged in SQS — one has to explicitly delete the message (or move it to another queue — such as a dead-letter queue) for it to be acknowledged and not re-sent once the visibility timeout expires.</p></div></div></section>
</section>
<p>The post <a rel="nofollow" href="https://pythonright.com/sqs-introduction-to-fifo-queues/">SQS— Introduction to FIFO Queues</a> appeared first on <a rel="nofollow" href="https://pythonright.com">PythonRight</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythonright.com/sqs-introduction-to-fifo-queues/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
