---
sidebar_position: 4
---

# Events and Topics

## Events
An event represents a fact. Events are immutable and never stay in one place. They always travel from one system to another system, carrying the state changes that happened in a database or application.
When talking about events inside a topic, the terms **event**, **record**, and **message** are used interchangeably.

By default, Kafka brokers can handle events of up to 1MB in size.

![Example of an event](./img/event_example.png)

## Streams
A Stream represents related events in motion.

## Topics
When an event stream enters Kafka, it is saved into a Topic. In Kafka, a topic is a materialised event stream, or in other words, a **topic is a stream at rest**.
Each event in a topic is kept for a certain period of time and gets discarded after such period ends. This period is called **retention**.

A topic groups related events together and durably stores them. The closest analogy for a Kafka topic is a directory which contains log files in a file system.

Topics are the central concept in Kafka that decouples Producers and Consumers.
A consumer pulls messages off of a Kafka topic while Producers push messages into it. A topic can have multiple producers and consumers.

![Kafka Topic](./img/topics.png)


## Infrastructure setup
You can create and manage Kafka Topics through [terraform-infra](https://github.com/theorchard/terraform-infra/blob/master/prod/kafka-infra/kafka-cluster/topics/main.tf).

```hcl
resource "kafka_topic" "my_topic" {
  name               = "my.topic.name"
  replication_factor = 3
  partitions         = 1
  config = {
    "max.message.bytes" = "15728640"
    "retention.ms"      = "86400000"
  }
}
```
