0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lesson

Introduction to Consumer Groups

Understand how Consumer Groups enable multiple consumers to process a stream cooperatively and reliably.

Introduction to Consumer Groups is a free Redis Caching & Messaging (Pub/Sub, Streams) lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Redis Caching & Messaging (Pub/Sub, Streams) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What are Consumer Groups?

Redis Streams are powerful for logging and event sourcing. But what if multiple applications or instances need to process the same stream data, without duplicating work?

This is where Consumer Groups come in. They are a core feature of Redis Streams designed for reliable, shared message processing.

The Challenge: Multiple Readers

Imagine two services, Service A and Service B, both needing to process every new order from an orders_stream.

If both services simply use XREAD, they would both receive and process all messages, leading to duplicated effort or inconsistent states.

  • How do they know which messages are already processed?
  • How do they share the workload?

Solving Shared Stream Processing

Consumer Groups provide a way for multiple clients (consumers) to jointly read from the same Redis Stream.

They ensure that:

  • Each message is delivered to only one consumer within the group.
  • The state (which messages are pending, which are acknowledged) is managed by Redis.
  • Consumers can recover and resume processing from where they left off.

Key Concepts: Group, Consumer, PEL

Let's define the core parts of a Consumer Group:

  • Stream: The Redis Stream holding the messages.
  • Consumer Group: A logical group of consumers processing a stream.
  • Consumer: An individual client instance within a group.
  • Pending Entry List (PEL): A list maintained by Redis for each consumer, tracking messages that have been delivered but not yet acknowledged.

Setting Up Your First Group

Before consumers can join, a Consumer Group must be created on a specific stream. We use the XGROUP CREATE command.

The MKSTREAM option automatically creates the stream if it doesn't exist.

XGROUP CREATE my_stream my_group 0 MKSTREAM

Populating the Stream

Let's add a few messages to our my_stream so we have something to read. Remember, XADD is how you add entries to a stream.

XADD my_stream * sensor_id 1 temp 25.5
XADD my_stream * sensor_id 2 temp 24.9
XADD my_stream * sensor_id 1 temp 26.1

Consumers Joining the Group

Consumers read from a group using the XREADGROUP command. You specify the group name, the consumer name, and the stream ID to start reading from.

The special ID > means "read only new, unread messages that have not been delivered to any other consumer in this group yet."

XREADGROUP GROUP my_group consumer1 COUNT 1 STREAMS my_stream >

Confirming Message Processing (XACK)

After a consumer processes a message, it must acknowledge it using XACK. This tells Redis the message is handled and can be removed from the consumer's Pending Entry List (PEL).

This is crucial for reliability and prevents messages from being re-delivered if a consumer crashes.

XACK my_stream my_group 1678881234567-0

Why XACK Matters

Acknowledging messages is vital for two main reasons:

  • Reliability: If a consumer fails before acknowledging, the message remains in its PEL and can be claimed by another consumer later.
  • Resource Management: Unacknowledged messages stay in the PEL, consuming memory. Acknowledging keeps the PEL clean and efficient.

Consumer Group Basics

Which Redis command is used to create a new Consumer Group for a stream?

Recap: Consumer Groups

In this lesson, you learned about Redis Consumer Groups and how they enable multiple consumers to reliably process messages from a single stream, ensuring each message is handled only once.

You now understand the roles of groups, consumers, and the Pending Entry List (PEL), and how to use XGROUP CREATE, XREADGROUP, and XACK.

Next, we'll dive deeper into implementing consumer group logic and handling pending messages!

Frequently asked questions

Is the “Introduction to Consumer Groups” lesson free?

Yes — the full text of “Introduction to Consumer Groups” is free to read here on the web, and the Redis Caching & Messaging (Pub/Sub, Streams) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Redis Caching & Messaging (Pub/Sub, Streams) course, upgrade to CoddyKit PRO.

What will I learn in “Introduction to Consumer Groups”?

Understand how Consumer Groups enable multiple consumers to process a stream cooperatively and reliably. You practise Redis Caching & Messaging (Pub/Sub, Streams) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Redis Caching & Messaging (Pub/Sub, Streams)?

No prior experience is required. Redis Caching & Messaging (Pub/Sub, Streams) on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Introduction to Consumer Groups” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Redis Caching & Messaging (Pub/Sub, Streams) lesson?

Yes. Every Redis Caching & Messaging (Pub/Sub, Streams) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Consumer Groups
  2. Implementing Consumer Group Logic
  3. Handling Pending Messages & Failures
  4. Monitoring Consumer Group Lag
← Back to Redis Caching & Messaging (Pub/Sub, Streams)