Skip to main content

Enable follower fetching in Aiven for Apache Kafka®

Enabling follower fetching in Aiven for Apache Kafka® allows your consumers to fetch data from the nearest replica instead of the leader, optimizing data fetching and enhancing performance.

Prerequisites

note

Follower fetching is supported on AWS (Amazon Web Services) and Google Cloud.

Identify availability zone

Before configuring client-side rack awareness, identify the AZs where your Kafka brokers run.

Enable follower fetching

Use one of the following methods to enable follower fetching on your Aiven for Apache Kafka service.

  1. Access the Aiven Console, and select your Aiven for Apache Kafka service.
  2. Click Service settings.
  3. Scroll to Advanced configuration and click Configure.
  4. Click Add configuration options.
  5. Select follower_fetching.enabled from the list and set the value to Enabled.
  6. Click Save configurations.

Client-side configuration

To enable follower fetching at the client level, configure the client.rack setting in the Apache Kafka client. Set the client.rack value to the corresponding AZ ID for AWS or AZ name for Google Cloud for each client. This ensures the client fetches data from the nearest replica.

Example configuration for your consumer properties file:

client.rack=use1-az1 # AWS example
client.rack=europe-west1-b # Google Cloud example

Example scenario: follower fetching in different AZs

Assume you have an Aiven for Apache Kafka cluster running in two AZs in the us-east-1 region for AWS and in the europe-west1 region for Google Cloud:

Cluster setup and consumer distribution

CloudRegionAZs for brokersAZs for consumers
AWSus-east-1use1-az1, use1-az2use1-az1, use1-az2, use1-az3
Google Cloudeurope-west1europe-west1-b, europe-west1-ceurope-west1-b, europe-west1-c, europe-west1-d

Consumer configuration

Set the client.rack value to the respective AZ ID for AWS or AZ name for Google Cloud for each consumer:

# AWS consumers in use1-az1
client.rack=use1-az1

# AWS consumers in use1-az2
client.rack=use1-az2

# AWS consumers in use1-az3
client.rack=use1-az3

# Google Cloud consumers in europe-west1-b
client.rack=europe-west1-b

# Google Cloud consumers in europe-west1-c
client.rack=europe-west1-c

# Google Cloud consumers in europe-west1-d
client.rack=europe-west1-d

Fetching behavior

CloudConsumer locationFetching behaviorNotes
AWSuse1-az1Fetch from the nearest replica in their AZReduced latency and network costs
AWSuse1-az2Fetch from the nearest replica in their AZReduced latency and network costs
AWSuse1-az3Fetch from the leader (no matching broker.rack)No follower fetching possible
Google Cloudeurope-west1-bFetch from the nearest replica in their AZReduced latency and network costs
Google Cloudeurope-west1-cFetch from the nearest replica in their AZReduced latency and network costs
Google Cloudeurope-west1-dFetch from the leader (no matching broker.rack)No follower fetching possible

Use follower fetching with Kafka Connect and MirrorMaker 2

Aiven for Apache Kafka® Connect and Aiven for Apache Kafka® MirrorMaker 2 use follower fetching when it is enabled on your Aiven for Kafka service.

Kafka Connect

Kafka Connect sets consumer.client.rack based on each node’s availability zone. To disable rack awareness for a specific connector, set:

{
"consumer.override.client.rack": "noop"
}

MirrorMaker 2

MirrorMaker 2 uses a rack ID based on the node’s availability zone when follower_fetching_enabled=true (default). You can override this by setting a rack_id in the integration configuration.

Rack awareness does not apply to external Kafka clusters.

See Configure rack awareness in MirrorMaker 2.

Verify follower fetching

After configuring follower fetching, monitor for a decrease in cross-availability zone network costs to verify its effectiveness.

Related pages