Lesson 3 of 7 Amazon Kinesis and Amazon MSK

Running Apache Kafka on AWS with Amazon MSK

This lesson explains how Amazon Managed Streaming for Apache Kafka (Amazon MSK) runs Kafka clusters for you, so teams with existing Kafka applications, skills or tooling can move to AWS without rewriting them.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe Kafka topics, partitions, brokers and consumer groups.
  • Choose between MSK Provisioned and MSK Serverless.
  • Describe how MSK Connect runs source and sink connectors.
  • Choose between Amazon MSK and Kinesis Data Streams.

Kafka concepts

Apache Kafka, which Amazon MSK runs, organises streaming data with a few concepts. A topic is a named stream of records, such as orders. Each topic is divided into partitions, ordered subsets that are the unit of parallelism: records in one partition stay in order, and different partitions can be processed at the same time. Brokers are the servers that store partitions and serve producers and consumers.

Consumers belong to a consumer group, which shares a topic's partitions among its members, so adding consumers spreads the load; each group reads the whole topic independently of other groups. A consumer's position in a partition is its offset, which it commits so that it can resume where it left off after a restart. The following table summarises the concepts.

ConceptMeaning
TopicA named stream of records
PartitionAn ordered subset of a topic; the unit of parallelism and ordering
BrokerA server that stores partitions and serves producers and consumers
Consumer groupA set of consumers that share a topic's partitions; each group reads the topic independently
OffsetA consumer's position in a partition, committed so that it can resume after a restart

The following diagram shows a topic's partitions and two consumer groups reading them independently.

A Kafka topic with three partitions, each stored on a broker. Records within a partition keep their order and are numbered by offset. Consumer group A has three consumers, one per partition; consumer group B has one consumer that reads all three partitions. Each group commits its own offsets and reads the topic independently.
The offsets and the placement of partitions on brokers are illustrative.
Match the pairs

Kafka vocabulary

Exam skills 1.1.1

Match each Kafka concept with its meaning.

Log in to try this activity Interactive activities are free with an account.

Cluster types

Amazon MSK offers two cluster types, which differ in who manages capacity. With MSK Provisioned, you choose the broker instance type, the number of brokers and the storage, and have fine control of Kafka's configuration; optional tiered storage moves older data to low-cost storage for long retention. It suits steady workloads and teams that tune Kafka. With MSK Serverless, capacity scales automatically and there are no brokers to size, which suits variable traffic and teams that want Kafka without capacity planning. The following table summarises the two types.

TypeCapacityBest for
MSK ProvisionedYou choose broker type, broker count and storage; optional tiered storage for cheap long-term retentionSteady workloads and fine control of Kafka configuration
MSK ServerlessCapacity scales automatically; no brokers to sizeVariable traffic and teams that want Kafka without capacity planning

Retention is configurable per topic and can be unlimited, which suits event sourcing and replay by many consumer groups.

Sort into groups

Provisioned or Serverless?

Exam skills 1.1.1 · 4.1.6

Choose the MSK cluster type for each team.

Log in to try this activity Interactive activities are free with an account.

MSK Connect

MSK Connect runs Kafka Connect connectors as a managed service. Sink connectors write topics to S3, OpenSearch or databases; source connectors, such as Debezium, capture changes from databases into topics. Connectors scale by workers and need no servers to manage.

Security

Amazon MSK secures clusters in several layers. Clients authenticate with IAM access control, which uses IAM policies to authorise actions on topics and consumer groups; with mutual TLS, using client certificates; or with SASL/SCRAM, using user names and passwords stored in AWS Secrets Manager. IAM access control is usually the simplest choice for clients running on AWS, because no separate credentials are needed.

Data is encrypted at rest with AWS KMS and in transit with TLS, both between clients and brokers and between brokers. Clusters run inside the customer's VPC, and multi-VPC private connectivity, based on AWS PrivateLink, lets clients in other VPCs or accounts connect privately without peering the networks.

Scenario questions

Securing MSK

Exam skills 1.1.1 · 4.1.2

Choose the MSK security option for each requirement.

Log in to try this activity Interactive activities are free with an account.

MSK or Kinesis?

MSK and Kinesis Data Streams both provide durable, ordered streams, so the choice is mainly about the ecosystem and control. Amazon MSK runs standard Apache Kafka, so it is the answer when existing applications already use Kafka's APIs and tools, when data must be retained for a very long time, or when detailed control of Kafka's configuration is needed. Kinesis Data Streams is a simpler AWS-native service with deep integrations, such as Lambda, Firehose and IAM, and little to operate. The following table summarises the choice.

ChooseWhen
Amazon MSKExisting Kafka applications, Kafka APIs and ecosystem tools, very long retention or fine configuration control
Kinesis Data StreamsA simpler, AWS-native service with deep integrations and little to operate
Sort into groups

MSK or Kinesis?

Exam skills 1.1.1

Choose the streaming service for each scenario.

Log in to try this activity Interactive activities are free with an account.
Worked example

Kinesis or MSK for a migration?

The choice between Kinesis and Amazon MSK depends on the existing environment. The following table identifies the appropriate service for each situation and the reason for the choice.

SituationChoiceWhy
A company runs Apache Kafka on premises with Kafka Connect and existing consumersAmazon MSKSame Kafka APIs; applications move without rewriting
A new AWS-native application with Lambda consumers and little operations staffKinesis Data Streams (on-demand)Serverless, simple integration
Events must be kept for months and replayed by many consumer groupsMSK (tiered storage)Long, cheap retention
Variable Kafka traffic, no wish to size brokersMSK ServerlessKafka without capacity planning

For the on-premises Kafka migration, MSK Connect can also take over the existing Kafka Connect connectors, for example an S3 sink that lands topics in the data lake, so the whole streaming estate moves with little change.

Check yourself

How are Kafka topics moved into S3 or databases without writing consumers?

Show answer

With MSK Connect, which runs Kafka Connect connectors as a managed service.

Exam Tips

Remember for the exam

  • Existing Kafka applications, or a requirement for Kafka APIs, point to Amazon MSK.
  • Kafka without capacity planning is MSK Serverless.
  • To move Kafka topics to S3 or databases with connectors, use MSK Connect.
  • To capture database changes into Kafka, run a Debezium source connector on MSK Connect.
  • For cheap long-term retention on provisioned clusters, use tiered storage.