Fundamentals 11 min read

Why You Don't Need to Send an SMS Immediately After an Order – Understanding Kafka and Message Queues

The article explains how using a message queue such as Kafka lets an order service return quickly by handling non‑critical tasks like SMS, points, and logging asynchronously, thereby improving latency, decoupling services, and smoothing traffic spikes while also covering Kafka's core concepts and trade‑offs.

YiSu Grain
YiSu Grain
YiSu Grain
Why You Don't Need to Send an SMS Immediately After an Order – Understanding Kafka and Message Queues

1. The problem without a message queue

When a user submits an order, the order service may synchronously call inventory, points, SMS, logistics, logging, and recommendation services before responding. This leads to slow response time, tight coupling, risk of being blocked by a slow downstream service, and inability to handle traffic spikes during promotions.

2. Which steps must be immediate?

The essential operations are creating the order, performing necessary inventory checks, handling payment or status updates, and returning a clear result to the user. Tasks such as sending SMS, adding points, writing logs, notifying recommendation systems, and generating reports can be deferred.

3. Introducing a message queue

By publishing an "order created" event to Kafka, the order service completes the core work and returns to the user while downstream services (inventory, points, SMS, logistics) consume the message at their own pace. This achieves asynchronous processing.

4. What a message queue does

Asynchronous execution : the main flow does not wait for all downstream work.

Decoupling : the order service does not need to know how each consumer is invoked.

Peak shaving : bursts of orders are buffered in the queue, allowing consumers to process at sustainable rates.

5. Core Kafka concepts

Topic : a logical channel for a class of messages (e.g., order‑topic, payment‑topic).

Partition : a topic is split into multiple partitions to enable parallel reads and writes.

Replica : each partition has a leader and follower replicas to provide fault tolerance.

Offset : a numeric position that acts as a consumer’s bookmark within a partition.

Consumer Group : a set of consumers that share the work of a topic; each message is processed by only one member of the group, while different groups can consume the same messages independently.

6. Why Kafka handles high throughput

Three reasons: sequential disk writes (append‑only log), parallelism across partitions, and batch processing of records, all of which reduce I/O overhead and enable scaling.

7. Trade‑offs and pitfalls

Message queues introduce new concerns: possible message loss, duplicate consumption, backlog buildup, ordering guarantees, and eventual consistency. Consumers must implement idempotence and retry logic, and operators may need to scale consumer instances to avoid accumulation.

8. Sample exam answer

For a scenario where synchronous calls cause slow order responses and overload during promotions, propose inserting Kafka: after the order is created, publish an event, return immediately, and let inventory, points, SMS, and logging services consume the event asynchronously. Highlight benefits of reduced latency, decoupling, and peak shaving, and note the need to handle reliability, duplication, and backlog.

9. Recap

Message queues are not a fancy add‑on; they extract non‑critical work from the main request path, allowing systems to stay fast and stable. Understanding Kafka’s five core concepts—Topic, Partition, Replica, Offset, Consumer Group—provides the foundation for designing such asynchronous, decoupled architectures.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KafkaMessage Queueasynchronous processingdecouplingPeak Shaving
YiSu Grain
Written by

YiSu Grain

A fleeting mayfly in the world, a single grain in the boundless sea.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.