Queuing chain pattern

A queuing chain pattern is applied when sequential processing needs to run on multiple systems that are linked together. Let's understand the queuing chain pattern using the example of an image-processing application. In an image-processing pipeline, sequential operations of capturing the image and storing it on a server, running a job to create different-resolution copies of the image, watermarking the image, and thumbnail generation are tightly linked to each other. A failure in one part can cause the entire operation to be disrupted.

You can use queues between various systems and jobs to remove a single point of failure and design true loosely coupled systems. The queuing chain pattern helps you to link different systems together and increase the number of servers that can process the messages in parallel. If there is no image to process, you can configure Auto Scaling to terminate the excess servers.

The following diagram shows a queuing chain pattern architecture. Here, the queue provided by AWS is called Amazon Simple Queue Service (SQS):

 

Queuing chain pattern architecture

The preceding architecture has the following steps:

  1. As soon as the raw image is uploaded to the server, the application needs to watermark all of the images with the company's logo. Here, a fleet of Amazon EC2 servers is running batch jobs to watermark all the images and push the processed image into the Amazon SQS queue.
  2. The second fleet of Amazon EC2 servers pulls the watermarked images from the Amazon SQS queue.
  3. The second fleet of EC2 workers has a job to process the image and create multiple variations with different resolutions.
  4. After encoding the images, the EC2 workers push the message into another Amazon SQS queue.
  5. As the image is processed, the job deletes the message from the previous queue to make up space.
  6. The final fleet of EC2 servers gets encoded messages from the queue and creates thumbnails along with the copyright.

The benefits of this architecture are as follows:

  • You can use loosely coupled asynchronous processing to return responses quickly without waiting for another service acknowledgment.
  • You can structure the system through the loose coupling of Amazon EC2 instances using Amazon SQS.
  • Even if the Amazon EC2 instance fails, a message remains in the queue service. This enables processing to be continued upon recovery of the server and creates a system that is robust to failure.

You may get fluctuations in application demand that can cause unexpected message loads. Automating your workload as per the queue message load will help you to handle any fluctuations. Let's learn more about the job observer pattern to handle such automation next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.130.13