A queue can be busy while one group cannot move
A synthetic artifact processor receives messages through an SQS FIFO queue. Messages for the same artifact family must remain ordered. One worker receives the first message in group parser-A and stalls before deleting it. Other workers continue processing group parser-B, but later messages in parser-A stop appearing. Increasing the consumer count does not remove the blocked group's dependency.
This is the consequence of choosing an ordering boundary. SQS uses MessageGroupId to distinguish ordered groups. An received and invisible message affects subsequent receives for its group while other groups can progress. The queue's total depth therefore tells only part of the story. A small number of blocked groups can contain the work a particular caller is waiting for even when overall throughput looks healthy.
This guide uses a deterministic queue model with synthetic identifiers. It illustrates ordering, visibility and deletion without contacting AWS or claiming service measurements. Real SQS batching, delivery timing and failures require an integration test. The original exercise is intentionally narrower than a complete queue emulator, making the assumptions easy to inspect.
The group identifier defines serialization
Choose a group key from the state that requires ordered updates. If two messages update the same artifact state machine, they may belong together. If they operate on independent artifacts, grouping all messages under one constant unnecessarily serializes them. Conversely, assigning a fresh group to every message removes the ordering relationship the application may depend on.
Do not confuse a group identifier with a deduplication identifier. The former defines ordering; the latter participates in duplicate-send handling. A unique deduplication identifier does not permit a blocked group's later message to overtake an earlier one. Likewise, a FIFO queue does not make arbitrary application side effects exactly once. Consumer retries and lost acknowledgements still require idempotent handling.
An application can also create false dependencies by choosing a key that is too broad. A category shared by thousands of independent artifacts may become a throughput bottleneck. Narrowing the key can help, but only if the state transitions are independent. Changing group assignment while old messages remain queued needs a migration plan; two ordering schemes can overlap and process updates concurrently.
Follow a six-message timeline
Create messages A1, A2 and A3 in group A, and B1, B2 and B3 in group B. Use a visibility duration of ten virtual seconds. At time zero a worker receives A1 and does not delete it. Another worker receives B1 and completes it. At time one, the next receive can obtain B2, while A2 remains behind A1.
At time ten, A1 becomes visible again in the teaching model. It is eligible for another receive; A2 does not automatically become the next safe update merely because time passed. If A1 succeeds and is deleted, the group can move forward. If A1 repeatedly fails, the group can remain stuck through multiple visibility cycles until the application or configured redrive behavior resolves it.
The offline fixture records message ID, group, receive count, visibility deadline and deletion. Its expected outcome is a trace showing B progressing while A waits. It does not simulate network latency or distributed queue internals. A fixed virtual clock makes the causal relationship explicit and permits exact assertions without sleeping for actual service timeouts.
Batch receives do not remove application ordering duties
AWS documents that one receive can return several messages from the same group. The returned messages preserve their FIFO order, and subsequent receives for that group are constrained while those messages are in flight. An application that immediately dispatches every message in the received batch to unrelated threads can still apply their side effects out of order.
Preserve sequential processing within each group while allowing independent groups to run concurrently. A batch can be partitioned by group, with one ordered handler per partition. Make the failure policy explicit: when an earlier message fails, do later messages in the same batch wait, return to visibility, or enter a documented recovery path? A generic thread pool does not answer that question.
Acknowledge only work whose outcome is known. Deleting a later message while an earlier dependent update failed may permanently discard the sequence needed to reconstruct state. If messages are independent despite sharing a group, reconsider the group design rather than relying on selective deletion to recover throughput. The queue contract and application dependency graph should agree.
Visibility is a lease on processing time
Choose visibility duration from the processing envelope and extend it when appropriate. A duration shorter than legitimate processing can allow another consumer to receive the same message while the first is still working. A very long duration delays recovery when a worker fails. Neither extreme removes the need for idempotency and a durable record of completed effects.
A consumer should know the difference between processing failure, delete failure and unknown outcome. If the side effect committed but deletion failed, the next delivery should discover the completed operation and acknowledge it safely. If the side effect's outcome is unknown, reconcile it through an operation key. Do not infer that a visibility timeout means nothing happened.
# Author: Sandeep Belgavi. Application-level idempotency illustration.
def apply_once(message, completed, effects):
key = message["operation_id"]
if key in completed:
return "already_applied"
effects.append(message["artifact_id"])
completed.add(key)
return "applied"
done, effects = set(), []
message = {"operation_id": "op-17", "artifact_id": "A-17"}
assert apply_once(message, done, effects) == "applied"
assert apply_once(message, done, effects) == "already_applied"
assert effects == ["A-17"]The in-memory illustration is not crash-safe. A deployed implementation needs an atomic relationship between the idempotency record and the effect, or a reconciliation protocol when they live in different systems. A local set demonstrates the decision only. Documenting that limit prevents an educational example from being mistaken for a transactional implementation.
Poison messages and recovery policy
A message can fail permanently because its schema is invalid or its required artifact no longer exists. Repeated delivery will not fix either condition. Decide how to quarantine such a message, preserve diagnostic evidence and resume the group. If redrive moves it elsewhere, understand that removing an ordered update can change the meaning of later updates.
For a sequence of state transitions, skipping one update may be invalid. The correct recovery could require rebuilding state, compensating an earlier effect or marking the entire sequence as failed. For independent refresh requests, dropping a superseded update may be acceptable. Those are domain semantics owned by the deterministic application, not properties that the FIFO queue can infer.
Keep operational tools scoped to exact message and group identifiers. A broad purge is not a routine remedy for one blocked group. Preserve enough synthetic evidence in tests to replay the failure, and enough production metadata to diagnose it under the application's retention policy. Avoid putting message bodies or user-specific identifiers into unbounded metric labels.
Verification and migration
Test independent groups, a stalled first message, visibility expiry, deletion, duplicate delivery and a failed batch prefix. Assert that later messages in a group do not pass the blocked predecessor in the model. Also assert that a different group progresses. A test that checks only total processed count misses the ordering property the queue was chosen to provide.
When migrating an existing standard queue workload, identify whether ordering is actually required and at what granularity. Add idempotency before treating FIFO as a correctness improvement. Observe age and processing progress per useful aggregation, alongside total queue metrics. Scale consumers only after checking whether the workload contains enough independent groups to use that capacity.
An agent can classify unstructured diagnostics before enqueueing a deterministic request, but it is unnecessary for deciding visibility, deletion or group ordering. Keep those mechanisms explicit. The useful question is not simply how many consumers are running; it is which independent ordering groups can make progress and what exact predecessor prevents the others from moving.