Если pod падает посередине обработки Kafka-сообщения, автокоммит отключён, что произойдёт с очередью, оставшимися pod и сообщением?
Asked at
AI answer
If the offset hasn’t been committed, Kafka considers the message unprocessed. After the consumer stops sending heartbeats and the timeout expires, the group performs a rebalance: the partitions assigned to the failed pod are reassigned to the remaining consumers. They continue reading from the last committed offset, so the message where the failure occurred will be read again. The other messages in the partition remain in Kafka and will be processed later; the queue itself is not deleted. Duplicates are possible if the handler performed external side effects before the failure. That’s why processing is usually made idempotent, and the offset is committed only after successful processing. Recovery time depends on the group settings and Kafka retention.
Also asked at GigaChat / Сбер
- app = FastAPI() def get_db(): db = SessionLocal() try: yield db finally: db.close() def heavy_text_parser(file_id: int, db: Session): # Parsing a file that takes 5 minutes parse_and_save(file_id, db) @app.post("/upload") async def upload_file( background_tasks: BackgroundTasks, db: Session = Depends(get_db) ): file_id = save_file_to_db(db) db.commit() background_tasks.add_task(heavy_text_parser, file_id, db) return {"status": "parsing started"}
- def extract_emails_from_huge_file(file_path: str) -> list[str]: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Заменяем переносы строк, чтобы текст был "сплошным" content = content.replace('\r\n', ' ').replace('\n', ' ') lines = content.split(' ') emails = [word for word in lines if '@' in word] return emails
Similar questions
- How can Kafka provide at-least-once message processing guarantees without data loss in the event of failures?
- How can you prevent message loss on the producer side (Transactional Outbox)?
- What happens if messages are reassigned to another consumer?
- What issues with message ordering or duplication did you encounter on the Kafka consumer side, and how did you address them?
- What should you do if Kafka lag is increasing? Have you encountered this?