CDP:Queuing Chain Pattern
Loose-Coupling of Systems
Problem to Be Solved
If performing sequential processing where processes running on multiple systems are linked together (for example, in the case of image processing, the sequential operations for uploading, storing, and encoding the image, creating a thumbnail, and the like), there will be a tendency for performance bottlenecks to result from having the systems tightly linked to each other. This tight linkage also complicates the recovery operations when there has been a failure. You can derive benefits in terms of performance and maintenance by loosely coupling the systems together whenever possible.
Explanation of the Cloud Solution/Pattern
You can achieve this loose loose coupling of systems by between systems using queues, and then exchanging messages that transfer jobs. This enables asynchronous linking of systems. This method lets you increase the number of virtual servers that receive and process the messages, enabling parallel processing, when necessary, letting you resolve bottlenecks easily. Even if there happened to be a failure in a virtual server, the unprocessed processed messages would still remain in the queue, making it easy to restart processing when the virtual server is restored.
While you can use this pattern even without Cloud technology, the queue itself is provided as an AWS Cloud service, making it substantially easier for you to use this pattern than it has been in the past, given the nature of Cloud technology in enabling flexible provisioning of virtual servers.
Use the the Amazon Simple Queue Service (SQS) to transfer a process from an EC2 instance for one process to the EC2 instance for the next process. SQS is the AWS queue service. The processing in EC2 is as follows: a job (message) is received --> the job is processed --> the job (message) is transmitted --> repeat. Depending on the nature of the job, you can run the processes on multiple EC2 instances.
- You can use asynchronous processing to return responses quickly.
- You can structure the system through loose coupling of simple processes (EC2 instances).
- You can handle performance and service requirements through merely increasing or decreasing the number of EC2 instances used in job processing.
- Even if an EC2 were to fail, a message (job) would remain in the queue service, enabling processing to be continued immediately upon recovery of the EC2 instance, producing a system that is robust to failure.
In systems where processes must be performed in strict sequence, you need to be aware that, in SQS, the sequence of messages when drawing from the queue is not completely guaranteed.
- You can combine this pattern with the Priority Queue Pattern.
- You can use the Amazon Simple Workflow (SWF) to provide complex workflows relatively easily, rather than just using simple queues.