Skip to main content
  1. 🔰Posts/
  2. 🗂️My Trainings/
  3. AWS Trainings and Certifications/
  4. 🏅AWS Certified Cloud Practitioner/

Cloud Integrations & Messaging

📚 Part 16 of 25: "AWS Cloud Practitioner" series.

·1224 words·6 mins

This section is about multiple applications communicating with each other.

📡 Useful TAG: Serverless
  1. Synchronous communication (application to application)
    • Can be problematic if there are sudden spikes of traffic
  2. Asynchronous / Event-based communication (application to queue to application)
    • It is called decoupling of applications
      • SQS: queue model
      • SNS: pub / sub model
      • Kinesis: real-time data streaming model
    • Those services can scale independently from our application

© Stéphane Maarek, DataCumulus

SQS #

SQS = Simple Queue Service. #

© Stéphane Maarek, DataCumulus
What is Amazon SQS

SQS - Standard Queue #

  • Oldest AWS offering (over 10 years old)
  • Fully managed, serverless service used to decouple applications
  • Sales from 1 message per second to 10,000s per second
  • Default messages retention: 4 days, maximum 14 days
  • No limit to how many messages can be in the queue
  • Messages are deleted after they’re read by consumers (applications)
  • Low latency
  • Consumers share the work to read messages and scale horizontally

© Stéphane Maarek, DataCumulus

SQS - FIFO Queue #

FIFO = First in First Out (ordering of messages in the queue) #

© Stéphane Maarek, DataCumulus
Messages are processed in order by the consumer.

  • Messages are processed in order by the consumer
  • Ordering by Message Group ID (all messages in the same group are ordered) – mandatory parameter

SQS - Consuming Messages #

  • Consumers (running on EC2 instances, servers, or AWS Lambda)…
  • Poll SQS for messages (receive up to 10 messages at a time)
  • Process the messages (example: insert the message into an RDS database)
  • Delete the messages using the DeleteMessage API

Amazon SQS - Security #

  • Encryption:
    • In‑flight via HTTPS
    • At‑rest with KMS keys
    • Optional client‑side encryption for full control
  • Access control:
    • IAM policies govern who can call SQS APIs
    • SQS access policies (like S3 bucket policies) enable cross‑account access
    • Useful for allowing services such as SNS or S3 to send messages to a queue

SQS - Message Visibility Timeout #

  • Once a consumer reads a message, it becomes invisible to others
  • Default visibility timeout is 30 seconds - the window to finish processing
  • When the timeout expires, the message becomes visible again
  • If processing isn’t finished in time, the message may be processed twice
  • Consumers can extend the timeout using ChangeMessageVisibility
  • Very long timeouts delay retries if a consumer crashes
  • Very short timeouts increase the chance of duplicate processing

© Stéphane Maarek, DataCumulus

Amazon SQS - Long Polling #

  • Consumers can wait for messages to arrive instead of returning immediately
  • This is Long Polling, which reduces API calls and improves efficiency/latency
  • Wait time ranges from 1-20 seconds (20 seconds recommended)
  • Preferable to short polling

SQS with ASG #

© Stéphane Maarek, DataCumulus

SQS as a buffer to database writes #

© Stéphane Maarek, DataCumulus

SQS to decouple between application tiers #

© Stéphane Maarek, DataCumulus

🙋🏻 Question: What SQS messages are exactly? For example - when processing video (relatively large file) between Front End -> SQS -> Back End - how SQS would be involved in this? Would it transfer the (large) file for example?

An SQS message is small metadata, typically:

  • a file name
  • a file path
  • an S3 object key
  • a job ID
  • a JSON payload describing work to do
  • a pointer to where the real data lives

🙋🏻 Question: How SQS fits into a video‑processing pipeline - as an example?

  • SQS messages are small (MAX 256 KB). They never contain large files.
  • SQS is used to send instructions or pointers to where the real data lives (usually S3).
  • SQS never moves the video.
    • S3 stores the video.
    • SQS tells the backend which video to process and what to do with it.

Example video-processing pipeline with SQS:

flowchart TD subgraph FrontEnd User[User uploads video] end subgraph Storage S3Upload[Video stored in S3] S3Output[Processed video stored in S3] end subgraph Queue SQSMsg[SQS message with metadata] end subgraph Backend WorkerPoll[Worker polls SQS] WorkerDownload[Worker downloads video] WorkerProcess[Worker processes video] Visibility[Worker extends visibility timeout during long processing] end User --> S3Upload S3Upload --> SQSMsg SQSMsg --> WorkerPoll WorkerPoll --> WorkerDownload WorkerDownload --> WorkerProcess WorkerProcess --> Visibility WorkerProcess --> S3Output
IMPORTANT
⬇️⬇️⬇️

‼️ Note: Worker extends visibility timeout during long processing was described earlier. Explainer:

  1. Video processing is long‑running

Transcoding a video can take minutes / tens of minutes / sometimes hours.

Default SQS visibility timeout is 30 seconds, which is nowhere near enough.

  1. Workers must extend visibility timeout

Workers typically call:

ChangeMessageVisibility

to extend the timeout periodically while processing.

This prevents:

  • another worker from picking up the same message
  • duplicate processing
  • corrupted output
  • race conditions
  1. It’s a core part of SQS‑based pipelines
Any long‑running job system using SQS must handle visibility timeout correctly.

More info: Visibility Timeout

Amazon Kinesis #

🏅 Solutions Architect Associate level extension: Kinesis - SAAC03.

Kinesis = real-time big data streaming. #

Managed service to collect, process and analyze real-time streaming data at any scale.

Amazon SNS #

SNS = Simple Notification Service. #

SNS is sending one message to multiple receivers.

© Stéphane Maarek, DataCumulus

  • The “event publishers” only sending message to one SNS topic
  • As many “event publishers” as we want to listen to the SNS topic notifications
  • Each subscriber to the topic will get all the messages
  • Up to 12,500,000 subscriptions per topic, 100,000 topics limit

© Stéphane Maarek, DataCumulus

SQS vs SNS vs Kinesis #

SQSSNSKinesis
Consumer “pull data”Push data to many subscribersStandard: pull data (2 MB per shard)
Data is deleted after being consumedUp to 12,500,000 subscribersEnhanced-fan out: push data (2 MB per shard per consumer)
Can have as many workers (consumers) as we wantData is not persisted (lost if not delivered)Possibility to replay data
No need to provision throughputPub/SubMeant for real-time big data, analytics and ETL
Ordering guarantees only on FIFO queuesUp to 100,000 topicsOrdering at the shard level
Individual message delay capabilityNo need to provision throughputData expires after X days
Integrates with SQS for fan out architecture patternProvisioned mode or on demand capacity mode
FIFO capability for SQS FIFO

Amazon MQ #

SQS and SNS are “cloud-native” services. Traditional applications running from on-premises may use open protocols, such as:

  • MQTT
  • AMQP
  • STOMP
  • Openwire
  • WSS

When migrating to the cloud, instead of re-engineering the application to use SQS and SNS, Amazon MQ can be used instead.

Amazon MQ is a managed message broker service for:

  • RabbitMQ

  • Active MQ

  • Amazon MQ doesn’t scale as much as SQS / SNS

  • Amazon MQ runs on servers, can run in Multi-AZ with failover

  • Amazon MQ has both - queue feature (~SQS) and topic features (~SNS)

Summary #

  • SQS
    • Queue service in AWS
    • Multiple Producers, messages kept up to 14 days
    • Multiple Consumers share the read and delete messages when done
    • Used to decouple applications in AWS
  • SNS
    • Notification service in AWS
    • Subscribers:
      • Email
      • Lambda
      • SQS
      • HTTP
      • Mobile
      • Others
    • Multiple Subscribers, sending all messages to all of them
    • No message retention
  • Kinesis
    • Real-time data streaming
  • Amazon MQ
    • Managed message broker for Active MQ and Rabbit MQ in the cloud (MQTT, AMQP protocols)

» Sources « #

» Disclaimer « #

This series draws heavily from Stephane Maarek’s Ultimate AWS Certified Cloud Practitioner course on Udemy.

His content was instrumental in helping me pass the certification.

About the instructor
🌐 Website📺 YouTube
💼 LinkedIn𝕏 x.com

ℹ️Shared for educational purposes only, no rights reserved.

AWS Certification Series »
AWS Cloud PractitionerAWS Solution Architect