14 - Decoupling Applications SQS SNS Kinesis MQ

Introduction to Messaging

awssqssnskinesisdecouplingsaa-c03

Overview

This section is about orchestrating work between your services using middleware. When you deploy multiple applications, they inevitably have to communicate with one another and share information and data. There are two patterns of application communication: synchronous and asynchronous (event based).


Synchronous vs Asynchronous Communication

Pattern How it works Example
Synchronous The application connects directly to another application A buying service talks straight to a shipping service: "something was bought, ship it"
Asynchronous / event based A middleware (a queue or something else) connects the applications The buying service puts "someone bought something" into a queue. The shipping service asks the queue whether something was bought recently and the queue returns it. The shipping service then does what it wants

In the asynchronous case the buying service and shipping service are not directly connected. Because they do not talk to one another, the communication is asynchronous.


Synchronous vs asynchronous communication

Synchronous: direct connection Buying service Shipping service a spike can overwhelm it Asynchronous: middleware in between Buying service Queuemiddleware Shipping service asks The two services are not directly connected and scale independently.
A queue between the buying and shipping services removes the direct connection.

Why Decouple

Synchronous communication becomes a problem when one service overwhelms the other, for example during a sudden spike of purchases.

Example: a video encoding service usually encodes 10 videos, but suddenly has to encode 1,000 videos. It is overwhelmed and you get outages.

When traffic spikes or is unpredictable, it is better to decouple your applications and let a decoupling layer scale for you:

Service Model
SQS Queue model
SNS Pub/sub model
Kinesis Real-time streaming, big data

With these, your services scale independently, and SQS, SNS and Kinesis themselves also scale very well.

Exam Pattern

Sudden spikes, unpredictable load, or a need to decouple applications -> put a decoupling layer in between: SQS (queue), SNS (pub/sub) or Kinesis (real-time streaming).


Questions & Answers

Q1: What are the two patterns of application communication?

Answer:

Synchronous (applications connect directly) and asynchronous / event based (a queue or other middleware sits between them).

Q2: Why is synchronous communication risky?

Answer:

A sudden spike (e.g. 1,000 videos to encode instead of the usual 10) can overwhelm the receiving service and cause outages.

Q3: Which AWS services decouple applications?

Answer:

SQS (queue model), SNS (pub/sub model), Kinesis (real-time streaming for big data). See the section overview.

Check yourself

Quiz

Flashcards

Click the card (or focus it), then use ← → to move and Space to flip.