AWS Builder Center
What Happens When an Event Arrives Out of Order on AWS?

What Happens When an Event Arrives Out of Order on AWS?

Learn why AWS events can arrive out of order and how to protect event-driven applications using SQS FIFO, version checks and safer processing patterns.

Series: AWS in Practice (By Deph..) (3 articles)

  1. 1
    What Happens When an Event Arrives Out of Order on AWS? This article
DevOps | AWS | Automation | n8n | Python Expert
An order is created, payment is completed and the customer cancels it a few minutes later. The application publishes an event for each change and several AWS services begin processing them. Everything appears normal until the order dashboard suddenly shows the cancelled order as paid again.
Nothing necessarily failed. The events were published, the consumers ran and the database accepted the updates. The problem is that the application processed an older event after a newer one and allowed it to overwrite the correct state.
This is one of the more frustrating problems in event-driven systems because it does not always produce an exception. CloudWatch logs may show successful Lambda invocations, queues may appear healthy and every individual component may be doing exactly what it was designed to do.
The problem is not always whether an event was delivered. Sometimes it is whether that event still represents the latest truth.

The Order Was Cancelled, So Why Does It Show as Paid?

Consider an order management application where changes to an order generate events consumed by a separate reporting service.
The order service publishes these events:
10:00:00 OrderCreated (version 1)
10:01:00 PaymentPaid (version 2)
10:03:00 OrderCancelled (version 3)
The reporting service is expected to maintain the latest order status. If events are processed in the same logical sequence, the final status is CANCELLED.
Now imagine the consumers process them in this order:
Expected processing:
OrderCreated
|
v
PaymentPaid
|
v
OrderCancelled
|
v
Status: CANCELLED
Actual processing:
OrderCreated
|
v
OrderCancelled
|
v
PaymentPaid
|
v
Status: PAID
The last update is wrong, even though the payment event was valid when it was originally produced.
This is the important distinction. An event can be authentic, correctly formatted and successfully delivered while still being too old to apply to the current state.
For systems involving payments, inventory, account permissions, subscriptions or shipment status, that can become a serious business problem.

Why Events Arrive Out of Order

Event-driven applications often have multiple producers, consumers, queues and processing paths. These components do not necessarily run at the same speed or complete their work in the same order.
Suppose an order service publishes three events through Amazon EventBridge. Different rules may route those events to separate consumers and one consumer may take longer because it needs to call a database or an external API.
Even if events are published close together, processing completion can happen in a different sequence.
Order Service
|
v
Event Router
|
+----> Event A ----> Lambda A ----> 800 ms
|
+----> Event B ----> Lambda B ----> 100 ms
|
+----> Event C ----> Lambda C ----> 250 ms
Event B may finish before Event A. If both consumers update the same business record, the application needs rules for deciding which update is still valid.
Several conditions can contribute to ordering problems:
  • Multiple consumers processing events concurrently.
  • Retries that delay an earlier event.
  • Temporary failures in downstream services.
  • Different processing times for different event types.
  • Multiple producers publishing changes to the same entity.
  • Events being replayed after a recovery operation.
  • Consumers updating the same database record independently.
This is not necessarily an AWS-specific defect. It is a consequence of distributed components operating independently.

Understand What AWS Actually Guarantees

Before designing a solution, it helps to understand the delivery behavior of the AWS messaging service being used.
Amazon SQS Standard queues prioritize high throughput and do not guarantee message ordering. Messages can arrive more than once and consumers must be prepared for that behavior.
Amazon SQS FIFO queues provide ordering within a message group. They are useful when related messages need to be processed sequentially, although the application still needs to handle processing failures and repeated attempts safely.
Amazon SNS FIFO topics also support ordered messaging for compatible destinations. Amazon EventBridge has traditionally been used for flexible event routing without assuming ordering across targets.
One important detail is that current EventBridge documentation also describes ordered FIFO subscribers for custom event buses. That means developers should check the capabilities and configuration of the event bus they are actually using rather than assume every EventBridge delivery path behaves identically.
AWS's  SQS, SNS and EventBridge decision guide  is a useful reference when comparing these communication models.
The larger lesson is that ordering guarantees are specific to a service, configuration and processing boundary. They should not be assumed to extend automatically across an entire application.

FIFO Queues Help, but They Do Not Fix Every Ordering Problem

When developers discover that events are arriving out of order, switching to an SQS FIFO queue is an understandable reaction.
FIFO queues can solve an important part of the problem. If messages belong to the same message group, SQS preserves their order of delivery and controls concurrent processing within that group.
For example, an order processing system could use the order ID as the message group ID:
SQS FIFO Queue
MessageGroupId: ORDER-101
|
+---- OrderCreated
+---- PaymentPaid
+---- OrderCancelled
MessageGroupId: ORDER-102
|
+---- OrderCreated
+---- PaymentPaid
Events for ORDER-101 are handled sequentially within their group, while events for ORDER-102 can be processed independently.
This is usually more practical than placing every message into one global group. A single group can restrict parallel processing because unrelated orders must wait behind one another.

Ordering Starts Before the Queue

There is another issue that is easy to overlook.
A FIFO queue preserves the order in which messages are accepted into the relevant message group. It cannot automatically reconstruct the intended business order if multiple producers publish changes inconsistently.
Imagine two services updating the same order:
Service A: OrderCancelled
Service B: PaymentPaid
If those services publish independently, the queue does not know which business operation logically came first unless the application establishes that order.
A FIFO queue can preserve a sequence. It cannot decide whether that sequence represents the correct business history.
For developers learning how queues and publish-subscribe systems fit into broader AWS applications, the  AWS developer roadmap  provides additional background on SQS, SNS, Lambda and decoupled services.
The next question is what happens when an old event reaches the consumer despite the messaging controls.

Give Events a Version, Not Just a Timestamp

One of the most useful patterns for protecting application state is to include a version number in each event.
Instead of publishing only the event type and order ID, the producer includes a version that represents the order's logical state.
{
"eventId": "evt-1003",
"eventType": "OrderCancelled",
"orderId": "ORDER-101",
"version": 3,
"occurredAt": "2026-10-31T10:03:00Z",
"status": "CANCELLED"
}
The consumer stores the latest version it has successfully applied.
Suppose the database currently contains:
{
"orderId": "ORDER-101",
"status": "CANCELLED",
"version": 3
}
An older payment event arrives with version 2. The consumer compares the incoming version with the stored version and refuses to overwrite the newer state.
The rule is straightforward:
Incoming version > Stored version
|
+----+----+
| |
Yes No
| |
v v
Apply Ignore stale
update event
This approach makes the consumer less dependent on message arrival order.
There is an important condition, though. The version must come from an authoritative source that controls the sequence of changes for that entity. If several independent producers invent their own version numbers, the comparison may not represent the true order of business changes.

Why Timestamps Are Not Always Enough

It is tempting to solve ordering by comparing event timestamps.
For example, the consumer could simply reject an event if its timestamp is earlier than the timestamp already stored in the database.
That can work when timestamps are assigned consistently by an authoritative source. It becomes less dependable when events originate from different systems with independent clocks.
Consider two producers:
Service A clock: 10:03:02
Service B clock: 10:03:01
The timestamps suggest that Service A's event happened later. That may not match the actual order of committed business changes.
Clock differences, network delays and timestamp assignment points can all affect the result.
A monotonic version number assigned during the authoritative state change is often a better choice when the application needs to establish which update supersedes another.
Timestamps remain useful for diagnostics, auditing and measuring delays. They simply should not be treated as proof of ordering unless the system guarantees their meaning.

Make the Database Reject Stale Updates

Checking an event's version inside Lambda is useful, but a separate read followed by an unconditional write can still create a race condition.
Imagine two Lambda invocations running concurrently:
Lambda A reads version 1
Lambda B reads version 1
Lambda B writes version 3
Lambda A writes version 2
Both functions believed their events were newer than the stored state when they performed the read. The older event still overwrote the newer one.
The version check needs to happen atomically with the database update.
Amazon DynamoDB conditional writes provide a practical way to enforce this.
Here is a simplified Python example using Boto3:
import boto3
from botocore.exceptions import ClientError
table = boto3.resource("dynamodb").Table(
"OrderReadModel"
)
def apply_order_event(event):
try:
table.update_item(
Key={
"orderId": event["orderId"]
},
UpdateExpression=(
"SET #status = :status, "
"#version = :version"
),
ConditionExpression=(
"attribute_not_exists(#version) "
"OR #version < :version"
),
ExpressionAttributeNames={
"#status": "status",
"#version": "version"
},
ExpressionAttributeValues={
":status": event["status"],
":version": event["version"]
}
)
return "APPLIED"
except ClientError as error:
if (
error.response["Error"]["Code"]
== "ConditionalCheckFailedException"
):
return "STALE_OR_DUPLICATE"
raise
This example assumes that the incoming event contains an authoritative, increasing version and a complete status value for the read model.
The database performs the comparison and update as one conditional operation. If a newer version already exists, an older event cannot overwrite it.
This protects against both out-of-order arrival and concurrent consumers attempting to update the same record.
There is one limitation worth making explicit. This pattern keeps the latest versioned snapshot, but it does not guarantee that every intermediate business transition was processed. If an application must execute every transition in sequence, it needs a stricter workflow or gap-handling strategy.

What If Version 5 Arrives Before Version 4?

Rejecting stale events protects the latest state, but it introduces another design question.
Suppose the consumer has version 3 and receives version 5 before version 4.
Should it apply version 5 immediately?
That depends on what the events represent.
If each event contains a complete snapshot of the entity's current state, applying version 5 may be acceptable. Version 4 is no longer needed to construct the latest view.
If the events represent individual changes, skipping version 4 could be dangerous.
Consider inventory:
Version 3: Stock = 20
Version 4: Remove 5 items
Version 5: Add 3 items
Applying only version 5 does not produce the correct inventory balance unless the event includes the resulting stock quantity.
For transition-based events, the consumer may need to wait for the missing version, retrieve authoritative state or move the entity into a recovery process.
A practical rule is to distinguish between two event designs:
Event design
Example
Handling a version gap
Complete state
Stock is now 18
May apply latest version
State change
Remove 5 units
Must account for missing changes
Business transition
Payment captured
May require ordered processing
Notification
Order status changed
Can often refresh current state
The event payload should make this distinction clear. Otherwise, consumers may silently lose information while trying to protect themselves from stale updates.

Idempotency and Ordering Are Different Problems

Out-of-order delivery is often discussed alongside duplicate events. They are related, but they are not the same problem.
Ordering asks whether an event is being applied at the correct point in the business sequence.
Idempotency asks whether processing the same event more than once causes an unwanted repeated effect.
Consider a payment event:
PaymentCaptured
Event ID: evt-2001
Amount: 100
If the event is delivered twice, the consumer should not record two separate payments merely because it received two messages.
Now imagine an older payment status event arrives after a refund event. Even if each event is processed only once, the final state can still become incorrect if the consumer applies them without checking their logical sequence.
A dependable consumer may therefore need both controls:
  • Event ID tracking to prevent repeated side effects.
  • Version checks to prevent stale state changes.
  • Business transition validation to reject impossible changes.
  • Retry handling that does not repeat completed external operations.
These controls solve different problems and none should be assumed to replace the others.

Event-Driven Systems Need a Clear Source of Truth

Ordering problems become harder when several services believe they own the same business state.
Imagine an order service, payment service, shipping service and reporting service all maintaining their own version of an order's status.
If each service can publish a new authoritative status without a shared ownership rule, consumers may receive conflicting events that cannot be resolved simply by comparing timestamps.
This is where service boundaries matter.
A practical architecture gives one service authority over a particular state transition and allows other services to publish facts within their own areas of responsibility.
For example:
Order Service
|
+---- Owns order lifecycle
|
v
Order Events
|
+----> Reporting Service
|
+----> Notification Service
|
+----> Analytics Service
The reporting service can maintain a read model, but it should not independently decide that an order is paid or cancelled.
Tools like  Data Assist  can simplify database connectivity through the Model Context Protocol (MCP), allowing AI-powered applications and assistants to interact with databases through a standardized interface. This can be useful when investigating event-processing issues, inspecting stored records and understanding how application state changes across services.
This principle becomes especially useful in larger event-driven serverless applications, where independently triggered functions and services react to changes without sharing a single execution path.
The more independently a system processes work, the more clearly it needs to define who owns each piece of business state.

Retries Can Reintroduce Old Events

Even after the initial event flow works correctly, retries can create ordering surprises.
Suppose version 2 fails because a downstream database is temporarily unavailable. Version 3 is processed successfully by another consumer. Later, version 2 is retried.
Without a version check, the recovered event can overwrite the correct state.
Version 2 ----> Failure ----> Retry later
Version 3 ----> Success
|
Version 2 --------------------+
|
v
Stale update risk
This becomes particularly important when using dead-letter queues and replay tools.
A dead-letter queue preserves failed messages for investigation, but replaying those messages does not make them current again. The business state may have changed substantially since the original processing attempt.
Before replaying events, the consumer should be able to distinguish between an event that still needs to be applied and one that has already been superseded.
For side-effecting operations, such as sending money or issuing refunds, version checks alone may not be enough. The system may also need a durable record of completed operations and explicit business recovery rules.

Design for Ordering Where It Actually Matters

Not every event in an AWS application needs strict ordering.
A notification service may be able to process unrelated notifications independently. An analytics pipeline may accept events arriving late and correct its aggregates afterward.
Order status changes, financial transactions, inventory adjustments and certain account operations can have much stronger sequencing requirements.
Instead of enforcing global ordering, identify the business entity that needs it.
For example:
Order ORDER-101
|
+---- Version 1
+---- Version 2
+---- Version 3
Order ORDER-102
|
+---- Version 1
+---- Version 2
There is usually no reason for ORDER-102 to wait for every event associated with ORDER-101.
This is why message group design matters in FIFO systems. A group identifier such as an order ID, account ID or customer ID can preserve relevant ordering while allowing independent groups to proceed concurrently.
The  Amazon SQS FIFO delivery documentation  explains how message groups affect delivery order, concurrent processing and the handling of messages that have not yet been deleted.
The objective is not to make every event globally sequential. It is to preserve the sequence that the business operation actually depends on.

How I Would Test an AWS Consumer for Out-of-Order Events

A successful test where events arrive in the expected order tells us very little about whether the consumer can handle production conditions.
I would test the same business entity with events deliberately delivered in different sequences.
For example:
Test 1:
Version 1 -> Version 2 -> Version 3
Test 2:
Version 3 -> Version 1 -> Version 2
Test 3:
Version 2 -> Version 2 -> Version 3
Test 4:
Version 3 -> Version 2 -> Version 1
Test 5:
Version 1 -> Version 3
-> Version 2 arrives later
For a complete-state read model, all five tests should eventually leave the record at the newest valid version.
For a transition-based workflow, some sequences should trigger buffering, recovery or rejection rather than silently skipping required operations.
I would also test concurrent writes against the same DynamoDB item. Two consumers trying to update the same entity at nearly the same time can reveal race conditions that ordinary sequential tests never expose.
Other useful scenarios include a failed event being replayed after several newer events, an event being delivered twice, a missing version never arriving and a downstream API completing an action just before the consumer times out.
These tests are more valuable than simply checking whether Lambda can process a valid event payload.

Monitoring Should Show More Than Successful Invocations

CloudWatch can tell us whether a Lambda function ran successfully, but successful execution does not always mean the business state is correct.
A consumer might process an outdated event, return success and leave no obvious technical error.
For version-aware consumers, I would track metrics such as:
  • Number of events applied successfully.
  • Number of stale events rejected.
  • Number of duplicate events detected.
  • Number of version gaps encountered.
  • Age of events when processing begins.
  • Number of failed conditional database writes.
  • Number of events waiting for recovery.
  • Number of replayed events that were already superseded.
These metrics help distinguish healthy late delivery from an actual application problem.
A sudden increase in stale events may indicate producer delays, retries, competing processing paths or a change in how events are published.
The useful question is not only whether events are being consumed. It is whether they are producing the correct business state.

The Right Fix Depends on What the Event Means

There is no single AWS configuration that solves every ordering problem.
If the application requires sequential processing within a business entity, SQS FIFO or another ordered processing mechanism may be appropriate.
If the application maintains a latest-state projection, authoritative versions and conditional database writes can protect against older updates.
If every intermediate transition matters, the consumer needs a way to detect gaps and recover missing events before continuing.
If several services publish conflicting changes, the system may need clearer ownership of the underlying business state rather than a different queue.
And if ordering does not matter for a particular consumer, enforcing it may only restrict throughput and make the application harder to operate.
The important decision is to identify which operations must happen in sequence, which events can be processed independently and which state changes must never be overwritten.

The Event Can Be Late Without Being Wrong

Out-of-order events are not necessarily a sign that an AWS service is malfunctioning. They are often a normal outcome of asynchronous processing, retries, independent consumers and distributed communication.
The real danger appears when the application assumes that the last event to arrive must represent the latest business state.
FIFO queues can preserve order within defined boundaries. Version numbers can identify stale updates. Conditional writes can prevent concurrent consumers from overwriting newer state. Idempotency can protect against duplicate side effects, while clear service ownership gives those events a meaningful source of truth.
A reliable event-driven application does not need every message to arrive at the perfect moment. It needs to know what to do when one does not.

Series: AWS in Practice (By Deph..) (3 articles)

  1. 1
    What Happens When an Event Arrives Out of Order on AWS? This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article