Distributed Queue Programming Models: Concepts, Architectures, and Practices

Distributed queue programming treats a queue as a fundamental, cross‑process abstraction, guiding developers to select synchronous or asynchronous, decoupled, persistent messaging solutions and offering four core models—point‑to‑point, producer‑consumer, publish‑subscribe, and MVC—while the article illustrates real‑world designs for billing, cache updates, and ticket processing.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
Distributed Queue Programming Models: Concepts, Architectures, and Practices

As a fundamental abstract data structure, queues are widely used in programming. In the era of big data, cross‑process and cross‑machine communication demands have grown, making distributed queue programming ubiquitous. However, two common oversights appear: developers often forget that a distributed queue is still a queue, and they overlook its existence when a concrete need arises.

The article starts from basic requirements, analyzing the origins, definition, structure, and variability of distributed queue programming models. It aims to provide a systematic thinking method to map concrete needs to queue models and to help readers quickly recognize various distributed queue scenarios.

When to Choose a Distributed Queue

When – Synchronous vs Asynchronous : Determine whether a message needs confirmation, how long confirmation may take, or whether sending blocks the next instruction. These heuristics guide the choice between synchronous and asynchronous communication, with asynchronous queues often being a viable option.

Who – Decoupling Sender and Receiver : If the sender does not need to know the receiver (or vice‑versa), a distributed queue offers unified middleware interfaces, reduces development cost, enables shared deployment, and improves flexibility and scalability.

Where – Message Persistence : When messages may accumulate or must not be discarded, a queue provides temporary storage.

How – Delivery Concerns : Availability, reliability, persistence, throughput, latency, and cross‑platform compatibility are key factors. If a solution meets these, a distributed queue is a simple choice.

Definition of Distributed Queue Programming

A distributed queue programming model consists of three roles: Sender (producer), Queue, and Receiver (consumer). The queue can be a traditional message broker (e.g., Kafka, RabbitMQ) or alternative forms such as a database table, a Redis cache, a data stream, or even an MVC model’s shared state.

Abstract Models

1. Point‑to‑Point Model : One sender, one queue, one receiver.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wckicsWt7GxFrsaPNZObCcPC5mW1Zbd9TpVPsvvicljiaQheIU8jL8O5v1g/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

2. Producer‑Consumer Model : Multiple producers/consumers share a single queue.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wc9seFozjp97z9lJn5sDjEibfn9mroLtNWX5Hic3U7MlNY7L2Fx5ziaCG4g/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

3. Publish‑Subscribe Model : One producer publishes messages to topics; each topic is consumed by a set of subscribers.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wclxfGOorU7evjLvg7wF2F9H4sibd5zIaogVuVt4vdS5RBI92TPOuiaP8g/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

4. MVC Model : Sender and receiver reside in the same entity but share a queue, similar to classic MVC.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wcbFiafRzRtfm9ibv8QhnhnARuTYrZ6lXRM6IRTx8n90xb5WO5fgCzVLxw/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

Programming Model vs. Asynchronous Programming

Distributed queue programming typically uses asynchronous mechanisms but is not equivalent to generic async programming, which may rely on hardware interrupts or intra‑process callbacks.

Programming Model vs. Stream Processing

Unlike stream frameworks (e.g., Spark Streaming, Apache Storm) that operate within a specific runtime, a distributed queue model is a requirement‑driven solution independent of any particular framework.

Practical Case – High‑Availability Billing System (Information Collection)

Challenges: high throughput, high availability, strong consistency, integrity (anti‑fraud), and persistence.

Design: Click/View collectors act as producers across multiple data centers; messages are sent via a message queue to a central IDC where the Billing service (consumer) processes them.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wc2siaibDC7c4lP7cQ327PojZFP0VU4ggtZ6Bys6a3O0kVC92aU2PSgIiaQ/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

Further optimizations include scaling via topic partitioning, global deduplication/anti‑fraud, and singleton service patterns for higher availability.

Distributed Cache Update

Problems: low consistency due to long TTLs, delayed availability of new data.

Solution: A dedicated Cache Updater service consumes keys from a high‑performance queue and updates the cache, with optional topic‑partitioned scaling and frequency control.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wc1dctPdeR9icCSWY7Bc4g5icKLvkzRTY1eW1Wbl7IYXYexGre4KXpHNqQ/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

Background Task Processing – Ticket/Work‑Order System

Challenges include data consistency, constraint handling, optimization, and response time under high concurrency.

Design: Rule generation (producer) creates messages representing user‑selected criteria; a Ticket Generator (consumer) reads from the queue to create work orders, optionally using a single‑instance deployment for global optimization.

<img src="http://mmbiz.qpic.cn/mmbiz_png/hEx03cFgUsXIQWfFC5Ogtrz1VFsgW1wcy8fCVvIfP62NJ9ibnDLWVtR0PsSkyeQQQHdlluWnuOiaic3dLjRJJGtzQ/0?wx_fmt=png" style="border:0;vertical-align:middle"/>

The architecture improves lock contention, enables centralized optimization, and enforces constraint integrity.

Conclusion

The article provides a systematic view of distributed queue programming, from conceptual models to real‑world implementations. The next part will discuss optimization techniques for producers, queues, and consumers.

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.

architectureBackend DevelopmentMessagingProducer Consumerdistributed queuePubSub
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

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.