Kafka consumers in FastAPI -> different services, different consumer, same producers

I have gone through these questions and some others, but unfortunately, I could not find an answer for my specific case even after reading the linked documents. Therefore, I believe this question is not a duplicate.

Can multiple Kafka consumers read same message from the partition

How multiple consumer group consumers work across partition on the same topic in Kafka?

How does Kafka achieve its parallelism with multiple consumption on the same topic same partition?

My question

We have a PHP side that handles Kafka producer operations and broadcasts messages related to product insert, update, and delete. This side has one topic named ‘products’ with three partitions: partition 0 for insert messages, partition 1 for update messages, and partition 2 for `delete’ messages.

On the other hand, we have additional services that need to listen to this topic. Each service performs operations on its own database independently, without relying on other services. All of these services handle their own insert, update, and delete operations. Before discussing my specific challenges, I’d like to mention the following points:

  • I am using FastAPI for my services.
  • Some of my services utilize Qdrant, while others use MongoDB as their
    database.
  • For my consumer client code, I am using aiokafka.

So my challenge is this:

1- auto-commit: True or False?

One of the options for configuring the consumer is the auto_commit setting. If I set it to false, all the messages in the partitions will remain as new ones even if my consumers read them. Initially, I thought this was the correct approach since my consumers are independent of each other. If one reads a message more quickly than others, it should not mark it as committed, allowing others to read it as well. However, after reading some questions and documentation, I realized that I may not fully understand the concept of auto_commit. Therefore, I’m unsure whether I should set it to true or false in order to receive messages in all my consumers.

2- group_id: what is it’s role here?

Now that each service has only one consumer, what should I name their group_id? Should they all have different group_ids? How does it affect the message retrieval scenario here? I mean, do these choices have any effects on how my consumers receive the messages?

3- Partitions: Should I listen to all of them with one consumer?

As the partitions on kafka producer are brodcasting different action messages, I am not sure if I should listen to each with separate consumer, or listen to all 3 with one single consumer. The msg.header contains the action name (insert, update, or delete), so I can know what is each message after receiving it.

Overall, I described my main concerns here, and the usecase. Any help, tip, or guide is deeply appreciated.

By the way, this is the test consumer that I have so far:

import sys, json, asyncio
from argparse import ArgumentParser, FileType
from configparser import ConfigParser
from aiokafka import AIOKafkaConsumer, TopicPartition

def encode_json(msg):
    to_load = msg.value.decode("utf-8")
    return json.loads(to_load)


async def main():
    topic_partition = TopicPartition(topic="products", partition=1)
    consumer = AIOKafkaConsumer(
        bootstrap_servers="host:port",
        enable_auto_commit=False,
        group_id="update",
        auto_offset_reset="earliest",
    )
    consumer.assign([topic_partition])
    await consumer.start()
    try:
        async for msg in consumer:

            print(
                msg.topic,
                msg.key.decode("utf-8"),
                msg.headers,
                # json.loads(msg.value()),
            )
    finally:
        consumer.stop()


asyncio.run(main())

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật