{"id":"asynchronism","title":"Asynchronism","sections":[{"id":"overview","title":"Overview","html":"<p class=\"figure\">\n  <img src=\"/repo/images/54GYsSx.png\" loading=\"lazy\" decoding=\"async\" alt=\"Diagram\">\n  <br>\n  <i><a href=\"http://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer\" target=\"_blank\" rel=\"noopener noreferrer\">Source: Intro to architecting systems for scale</a></i>\n</p>\n<p>Asynchronous workflows help reduce request times for expensive operations that would otherwise be performed in-line.  They can also help by doing time-consuming work in advance, such as periodic aggregation of data.</p>","headings":[]},{"id":"message-queues","title":"Message queues","html":"<h3 id=\"message-queues\">Message queues</h3>\n<p>Message queues receive, hold, and deliver messages.  If an operation is too slow to perform inline, you can use a message queue with the following workflow:</p>\n<ul>\n<li>An application publishes a job to the queue, then notifies the user of job status</li>\n<li>A worker picks up the job from the queue, processes it, then signals the job is complete</li>\n</ul>\n<p>The user is not blocked and the job is processed in the background.  During this time, the client might optionally do a small amount of processing to make it seem like the task has completed.  For example, if posting a tweet, the tweet could be instantly posted to your timeline, but it could take some time before your tweet is actually delivered to all of your followers.</p>\n<p><strong><a href=\"https://redis.io/\" target=\"_blank\" rel=\"noopener noreferrer\">Redis</a></strong> is useful as a simple message broker but messages can be lost.</p>\n<p><strong><a href=\"https://www.rabbitmq.com/\" target=\"_blank\" rel=\"noopener noreferrer\">RabbitMQ</a></strong> is popular but requires you to adapt to the 'AMQP' protocol and manage your own nodes.</p>\n<p><strong><a href=\"https://aws.amazon.com/sqs/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SQS</a></strong> is hosted but can have high latency and has the possibility of messages being delivered twice.</p>","headings":[{"id":"message-queues","title":"Message queues","depth":3}]},{"id":"task-queues","title":"Task queues","html":"<h3 id=\"task-queues\">Task queues</h3>\n<p>Tasks queues receive tasks and their related data, runs them, then delivers their results.  They can support scheduling and can be used to run computationally-intensive jobs in the background.</p>\n<p><strong><a href=\"https://docs.celeryproject.org/en/stable/\" target=\"_blank\" rel=\"noopener noreferrer\">Celery</a></strong> has support for scheduling and primarily has python support.</p>","headings":[{"id":"task-queues","title":"Task queues","depth":3}]},{"id":"back-pressure","title":"Back pressure","html":"<h3 id=\"back-pressure\">Back pressure</h3>\n<p>If queues start to grow significantly, the queue size can become larger than memory, resulting in cache misses, disk reads, and even slower performance.  <a href=\"http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html\" target=\"_blank\" rel=\"noopener noreferrer\">Back pressure</a> can help by limiting the queue size, thereby maintaining a high throughput rate and good response times for jobs already in the queue.  Once the queue fills up, clients get a server busy or HTTP 503 status code to try again later.  Clients can retry the request at a later time, perhaps with <a href=\"https://en.wikipedia.org/wiki/Exponential_backoff\" target=\"_blank\" rel=\"noopener noreferrer\">exponential backoff</a>.</p>\n<h3 id=\"disadvantages-asynchronism\">Disadvantage(s): asynchronism</h3>\n<ul>\n<li>Use cases such as inexpensive calculations and realtime workflows might be better suited for synchronous operations, as introducing queues can add delays and complexity.</li>\n</ul>\n<h3 id=\"sources-and-further-reading-11\">Source(s) and further reading</h3>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=1KRYH75wgy4\" target=\"_blank\" rel=\"noopener noreferrer\">It's all a numbers game</a></li>\n<li><a href=\"http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html\" target=\"_blank\" rel=\"noopener noreferrer\">Applying back pressure when overloaded</a></li>\n<li><a href=\"https://en.wikipedia.org/wiki/Little%27s_law\" target=\"_blank\" rel=\"noopener noreferrer\">Little's law</a></li>\n<li><a href=\"https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function\" target=\"_blank\" rel=\"noopener noreferrer\">What is the difference between a message queue and a task queue?</a></li>\n</ul>","headings":[{"id":"back-pressure","title":"Back pressure","depth":3},{"id":"disadvantages-asynchronism","title":"Disadvantage(s): asynchronism","depth":3},{"id":"sources-and-further-reading-11","title":"Source(s) and further reading","depth":3}]}],"sourceFiles":[]}