DEV Community

Anupa Supul
Anupa Supul

Posted on

How Do Large Applications Process Work in the Background? Understanding Amazon SQS, SNS & EventBridge

When I started learning AWS, I focused mainly on deploying applications, building APIs, and connecting databases.

But then I started thinking about something interesting.

What happens when an application needs to perform several tasks without making the user wait for everything to finish?

Imagine ordering a product from an online store. After placing the order, the system might need to update inventory, send a confirmation email, generate an invoice, and notify the delivery team.

Should the customer wait until every single task is completed?

Probably not.

This is where event-driven architecture and messaging services become useful.

In this article, I'll explore three AWS services that help applications communicate and process work more efficiently:

  • Amazon SQS — queues messages for processing.
  • Amazon SNS — distributes messages to multiple subscribers.
  • Amazon EventBridge — routes events to targets based on rules.

1. Why Do Applications Need Background Processing?

Consider a simple application where every operation happens inside one request.

Customer places an order
          |
          v
      Save order
          |
          v
   Update inventory
          |
          v
   Send confirmation
          |
          v
   Generate invoice
          |
          v
   Return response
Enter fullscreen mode Exit fullscreen mode

If each operation runs sequentially, the customer may need to wait for all of them. If an external email service is slow, the entire request could take longer.

It also creates tight coupling: a problem in one dependency can affect the main request.

Instead, we can separate the immediate operation from background work.

Customer places an order
          |
          v
       Save order
          |
          v
   Queue background work
          |
          v
  Return response to customer
          |
          v
   Process tasks separately
Enter fullscreen mode Exit fullscreen mode

Now the application can respond after completing the necessary synchronous work, while other operations happen independently.

This is one of the main ideas behind asynchronous processing.

2. Amazon SQS — Let Messages Wait in a Queue

Amazon Simple Queue Service (SQS) is a managed message queuing service.

Think of it as a waiting line for tasks. A producer sends a message to the queue, and a consumer retrieves and processes it.

For example:

Order API
    |
    v
Amazon SQS Queue
    |
    v
Order Processing Worker
    |
    v
Update Inventory
Enter fullscreen mode Exit fullscreen mode

The API doesn't need to wait for the worker to finish processing the message.

Why is SQS useful?

  • It helps decouple application components.
  • Messages can wait until consumers are ready to process them.
  • It helps absorb temporary traffic spikes.
  • Failed messages can be retried.
  • Dead-letter queues can isolate messages that repeatedly fail.

SQS offers Standard queues and FIFO queues. Standard queues provide high throughput with at-least-once delivery, so consumers should be designed to handle duplicate messages. FIFO queues support ordering within message groups and deduplication features, with their own throughput and configuration considerations.

One important concept is the visibility timeout. When a consumer receives a message, the message becomes temporarily invisible to other consumers. If processing succeeds, the consumer deletes it. If the message isn't deleted before the visibility timeout expires, it can become available again.

That is why reliable message processing needs error handling and idempotency.

3. Amazon SNS — Send One Message to Multiple Subscribers

Amazon Simple Notification Service (SNS) is a managed publish/subscribe messaging service.

Instead of placing work in a queue for one consumer pattern, SNS can distribute a published message to multiple subscribers.

Imagine an order has been placed. Several systems need to react:

  • A notification service sends a confirmation.
  • An analytics service records the event.
  • Another service starts a fulfilment workflow.

SNS can help distribute the notification to these subscribers.

              Order Service
                    |
                    v
                 Amazon SNS
                    |
          +---------+---------+
          |         |         |
          v         v         v
        SQS A     Lambda    Email
      Queue       Function  Endpoint
Enter fullscreen mode Exit fullscreen mode

SNS supports different subscription types, including SQS queues, Lambda functions, HTTP/S endpoints, and email, depending on the configuration and use case.

Why is SNS useful?

SNS is a good fit when multiple subscribers need to receive a notification about the same event.

For example, an order service can publish an OrderPlaced notification without needing to know the internal implementation of every subscriber.

That reduces direct dependencies between services.

A key distinction: SNS distributes messages; it is not a general-purpose durable work queue in the same way SQS is. Combining SNS with SQS can be useful when multiple consumers need their own queues and independent processing.

4. Amazon EventBridge — Route Events Based on Rules

Amazon EventBridge is a serverless event bus service that routes events to targets using rules.

An event describes something that happened, such as:

  • An order being placed.
  • A payment succeeding.
  • A file being uploaded to Amazon S3.
  • A scheduled task reaching its execution time.

EventBridge can inspect an event and route it to the targets whose rules match.

For example:

       OrderPlaced Event
               |
               v
       Amazon EventBridge
               |
        +------+------+
        |             |
        v             v
   Order Processor  Analytics
       Lambda        Target
Enter fullscreen mode Exit fullscreen mode

You can define rules that match event attributes and send matching events to supported targets.

EventBridge is particularly useful for reacting to events from AWS services, your own applications, and supported SaaS integrations.

It also supports scheduled and time-based event patterns through its scheduling capabilities.

When should you use EventBridge?

Use it when you want to route events based on what happened, without tightly connecting the event producer to every downstream service.

For example, an application could react differently to OrderPlaced, PaymentFailed, and OrderCancelled events.

5. SQS vs SNS vs EventBridge

These services can work together, but they solve different problems.

Feature Amazon SQS Amazon SNS Amazon EventBridge
Main purpose Queue messages for processing Distribute messages to subscribers Route events using rules
Core pattern Queue and consumer Publish/subscribe Event bus and targets
Typical use Background jobs Notifications to multiple subscribers Reacting to application or AWS events
Message handling Consumers poll or use supported integrations Pushes notifications to subscribers Routes matching events to targets
Useful feature Visibility timeout and dead-letter queues Multiple subscribers and filtering Event pattern matching and routing

Here's the simple mental model I use:

  • SQS: "Process this work when you're ready."
  • SNS: "Send this notification to these subscribers."
  • EventBridge: "When this event happens, route it to the appropriate target."

6. How They Work Together in a Real Application

Let's return to our online store.

After a customer places an order, the API saves the order and publishes an event. Different services can then handle different responsibilities.

AWS event-driven architecture showing API Gateway, Lambda, DynamoDB, SQS, SNS, and EventBridge

An e-commerce application can use queues for background processing, notifications for multiple subscribers, and event rules to route events.

Here is a simplified architecture diagram in text form:

React Frontend
      |
      v
API Gateway
      |
      v
AWS Lambda
      |
      v
Save Order in DynamoDB
      |
      v
Publish OrderPlaced Event
      |
      v
Amazon EventBridge
      |
      +-------------------+
      |                   |
      v                   v
Order Processing       Analytics
      |
      v
Amazon SQS
      |
      v
Background Worker
      |
      v
Update Inventory / Fulfil Order
Enter fullscreen mode Exit fullscreen mode

A separate notification workflow could use SNS to distribute an order notification to multiple subscribers.

The exact architecture depends on the requirements. For example, an SQS queue can be an EventBridge target, allowing the event to be routed to a durable queue for later processing.

This architecture separates the order API from slower background tasks. It also lets different components scale and fail independently to a degree, provided that retries, error handling, and downstream dependencies are designed correctly.

What happens when the order is placed?

  1. The React frontend sends a request to API Gateway.
  2. Lambda validates the request and saves the order in DynamoDB.
  3. The application publishes an order event.
  4. EventBridge evaluates its rules and routes matching events to configured targets.
  5. Background processing runs independently, potentially through SQS and a worker.
  6. SNS can distribute notifications to subscribers when needed.

One important production consideration: don't assume that saving an order and publishing an event are automatically one atomic operation. If the database write succeeds but event publishing fails, the system may need a reliable publishing strategy, such as the transactional outbox pattern, to avoid losing important events.

7. Reliability: Retries, Dead-Letter Queues, and Duplicate Messages

Asynchronous systems are powerful, but they introduce their own challenges.

What happens if a worker crashes while processing a message? What if a message is delivered more than once?

These are normal distributed-system problems.

Retries

Temporary failures may be resolved by retrying the operation. However, retries should be configured carefully to avoid overwhelming a failing dependency.

Dead-letter queues

A dead-letter queue (DLQ) can hold messages that exceed the configured retry or receive-count threshold. This gives you a way to investigate and recover messages that repeatedly fail.

Idempotency

An operation is idempotent when repeating it produces the same intended result rather than performing the effect multiple times.

For example, if a worker receives the same order-processing message twice, it should not deduct inventory twice unintentionally.

SQS Standard queues can deliver duplicate messages, and other event-driven workflows can also retry delivery. Design consumers with this possibility in mind.

Monitoring

CloudWatch metrics, logs, and alarms can help identify growing queue backlogs, processing failures, throttling, and other problems.

The goal isn't to assume messages will never fail. It's to design the application so failures can be detected and handled safely.

8. When Should You Use Each Service?

Choose the service based on the communication problem you're trying to solve.

Use Amazon SQS when:

  • Work needs to wait until a consumer is ready.
  • You want to separate request handling from background processing.
  • You need to buffer traffic spikes.
  • Consumers need to retry processing failed messages.

Use Amazon SNS when:

  • One message needs to reach multiple subscribers.
  • You want a publish/subscribe communication pattern.
  • Multiple systems need to react to the same notification.

Use Amazon EventBridge when:

  • Events need to be routed based on their content.
  • AWS services or applications generate events.
  • Different event types need different processing workflows.
  • You want event-driven integration without hardcoding every destination into the producer.

These are common patterns, not strict boundaries. Real architectures often combine these services.

9. My Main Takeaways

As I continue learning AWS, I'm realizing that building a reliable application involves more than deploying a backend and connecting a database.

It also means understanding how different components communicate, how failures are handled, and how background work can be processed without slowing down the user experience.

Here is the mental model I use:

  • Amazon SQS queues work for consumers.
  • Amazon SNS distributes messages to subscribers.
  • Amazon EventBridge routes events using rules.
  • AWS Lambda can execute event-driven processing.
  • Amazon DynamoDB can store application data.
  • Amazon CloudWatch helps monitor and troubleshoot the system.

The key lesson is that these services solve different communication problems. Choosing the right one depends on whether you need a queue, a notification mechanism, or event-based routing.

And in production, retries, duplicate handling, permissions, monitoring, and cost still matter.

I'm documenting my AWS learning journey one concept at a time. If you're learning cloud computing too, I'd love to hear what you're building and which AWS services you're exploring.

Top comments (0)