Skip to main content

Kafka client library based on confluent-kafka with retry functionality

Project description

Retriable Kafka Client

This is an opinionated wrapper for confluent_kafka Python library. It only uses specific parts of the underlying library while introducing additional functionalities to these selected parts.

Features

The aim is to provide a fault-tolerant platform for parallel message processing.

Parallel processing

Each consumer requires an executor pool, which will be used for message processing. Each consumer can consume from multiple topics and processes the messages from these topics by a single callable. The callable must be specified by the user of this library.

The library also ensures exactly-once processing when used correctly. To ensure this, the tasks should take short enough time that all of them finish before the cluster forces rebalancing. The library tries to finish tasks from revoked partitions before the rebalance while stopping additional non-started tasks. The default timeout for each task to finish is 30 seconds, but can be changed. Kafka cluster behavior change may also be needed with longer tasks. This behavior only appears during rebalancing and graceful stopping of the consumer.

Fault-tolerance

Each consumer accepts configuration with retry topics. A retry topic is a Kafka topic used for asynchronous retrying of message processing. If the specified target callable fails, the consumer will commit the original message and resends the same message to a retry topic with special headers. The headers include information about the next timestamp at which the message should be processed again (to give some time to the error to disappear if the processing depends on some outside infrastructure).

The retry topic is polled alongside the original topic. If a message contains the special timestamp header, its Kafka partition of origin will be paused and the message will be stored locally. The processing will resume only after the specified timestamp passes. The message will not be processed before the timestamp, it can only gather delay (depending on the occupation of the worker pool). Once the message is sent to the pool for re-processing, the consumption of the blocked partition is resumed.

This whole mechanism does not ensure message ordering. When a message is sent to be retried, another message processing from the same topic is still unblocked.

Message splitting

This library also supports sending large messages to topics which don't have the capacity to process these messages as whole. To do this, producers are configurable to automatically split messages according to message size.

This feature is custom and is therefore turned off by default. The only place this feature is always enabled are retry-topics, which are meant to be consumed only by clients using this library.

The chunked messages have 3 additional headers:

  • Group ID (uuid4 value)
  • Chunk ID (serial number of the chunk within group, starting with 0)
  • Number of chunks (is always +1 from the last chunk ID)

Message is deserialized and processed only if all expected chunks have been found.

Contributing guidelines

To check contributing guidelines, please check CONTRIBUTING.md in the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retriable_kafka_client-0.6.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retriable_kafka_client-0.6.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file retriable_kafka_client-0.6.0.tar.gz.

File metadata

  • Download URL: retriable_kafka_client-0.6.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retriable_kafka_client-0.6.0.tar.gz
Algorithm Hash digest
SHA256 42e22675c917769b5fd0296c94dadea8bfd8d01039f42ccf9c222d9b9c72022b
MD5 0be335769e5bc3c9f657d73470f7d8d1
BLAKE2b-256 0e3b72b616316333ee11cfd939d172ca5a9d79ff06a6ca3bd183ef5551f26c45

See more details on using hashes here.

File details

Details for the file retriable_kafka_client-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: retriable_kafka_client-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retriable_kafka_client-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c160fdf38d7da5defb8d2f9c743e2e1e7ed605c93ab110b1d5d0dcdfef176156
MD5 8322eb7cfc5ca12ae15064fb2556d33c
BLAKE2b-256 36dcbc43d64eb9bb416111fa50edd97bf5a6978131188b9d4b1963803b0da089

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page