Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

2.2.1.3. Decoupling with SQS and SNS

2.2.1.3. Decoupling with SQS and SNS

💡 First Principle: Decoupling separates application components for independent operation, improving fault tolerance, scalability, and maintainability via asynchronous communication, preventing cascading failures.

Decoupling is an architectural principle that aims to reduce direct dependencies between different components or microservices within an application. This allows each component to operate, scale, and fail independently without affecting others. Asynchronous communication is key to achieving this.

  • Amazon SQS (Simple Queue Service): A fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. It stores messages reliably until processed by a consumer, allowing independent producer/consumer operation. This buffers workloads and prevents backlogs from overwhelming components.
  • Amazon SNS (Simple Notification Service): A fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication. It uses a publish/subscribe model, allowing a publisher to send messages to a single topic for distribution to multiple subscribed endpoints (e.g., Lambda functions, SQS queues, HTTP endpoints, email). This is often called fan-out messaging.
Key Services for Decoupling:
  • "Amazon SQS": Message queuing, producer-consumer decoupling, reliable buffering.
  • "Amazon SNS": Publish/subscribe, fan-out messaging, A2A/A2P communication.

Scenario: An e-commerce site uses Amazon SQS to queue new customer orders, allowing the front-end to remain responsive while a separate backend service asynchronously processes payments and inventory updates.

Visual: Decoupling with SQS and SNS
SQS Queue Types and Message Handling:
  • Standard queue: Nearly unlimited throughput, at-least-once delivery (a message can occasionally be delivered more than once) and best-effort ordering.
  • FIFO queue: Strict first-in-first-out ordering (within a message group) and exactly-once processing (duplicates sent within the 5-minute deduplication interval are discarded), at lower throughput than standard. Choose it when order and no-duplicates both matter.
  • Visibility timeout: Receiving a message does not delete it — SQS hides it from other consumers for the visibility timeout (default 30 seconds). The consumer deletes it after successful processing; if the consumer crashes first, the message becomes visible again when the timeout expires and another consumer can pick it up.
  • Dead-letter queue (DLQ): Once a message has been received more times than the redrive policy's maxReceiveCount without being deleted, SQS moves it to the DLQ for inspection, so a repeatedly failing ("poison") message stops cycling through the main queue.
  • Long polling: A receive call waits up to 20 seconds for a message to arrive, cutting empty responses and cost; it does not change ordering or delivery guarantees.

⚠️ Common Pitfall: Using SQS as a pub/sub mechanism. SQS is a queue (one consumer per message). Use SNS for true fan-out (publish/subscribe).

Key Trade-Offs:
  • Loose Coupling vs. Increased Complexity: Decoupling adds more components (queues, topics) and requires asynchronous programming patterns, which can increase architectural complexity but significantly improves resilience and scalability.

Reflection Question: How does decoupling with messaging services like Amazon SQS and Amazon SNS enhance system resilience and enable independent scaling of microservices by preventing cascading failures and buffering workloads?

See how it connects
Alvin Varughese
Written byAlvin Varughese
Founder•20 professional certifications