<a id="streams-code-examples"></a>

# Kafka Streams Code Examples for Confluent Platform

Kafka Streams code examples are runnable Java programs and tutorials that
show how to implement common stream processing patterns, including
routing, transforming, aggregating, joining, and windowing events from
Apache Kafka® topics. The following sections link to curated examples on
Confluent Developer and GitHub, organized by pattern, that you can use
as templates for your own Kafka Streams applications on Confluent Platform.

## Confluent for VS Code

Use the Confluent for VS Code extension to generate a new Kafka Streams
application that reads messages from a Kafka topic, performs a simple
transformation, and writes the transformed data to another topic. This option
is ideal if you’re learning about Kafka Streams.

For more information, see [Confluent for VS Code with Confluent Platform](../clients/vscode/overview.md#cp-vscode-extension).

## Getting started examples

Many Kafka Streams examples on [Confluent Developer](https://developer.confluent.io/tutorials/#kafka-streams) provide full code examples with step-by-step instructions.

The code repository for the Kafka Streams examples is available on
[GitHub](https://github.com/confluentinc/tutorials/).

### Routing

* [Split a stream into substreams](https://developer.confluent.io/confluent-tutorials/splitting/kstreams/)
* [Merge many streams into one](https://developer.confluent.io/confluent-tutorials/merging/kstreams/)
* [Choose the output topic dynamically](https://developer.confluent.io/confluent-tutorials/dynamic-output-topic/kstreams/)
* [Filter a stream of events](https://developer.confluent.io/confluent-tutorials/filtering/kstreams/)
* [Find distinct events in a time window](https://developer.confluent.io/confluent-tutorials/deduplication-windowed/kstreams/)

### Transforming

* [Uppercasing a stream of events](https://developer.confluent.io/confluent-tutorials/creating-first-apache-kafka-streams-application/kstreams/)
* [Convert a KStream to a KTable](https://developer.confluent.io/confluent-tutorials/streams-to-table/kstreams/)
* [Transform a stream of events](https://developer.confluent.io/confluent-tutorials/transforming/kstreams/)
* [Find distinct events in a time window](https://developer.confluent.io/confluent-tutorials/deduplication-windowed/kstreams/)

### Aggregations

* [Count events by grouping key](https://developer.confluent.io/confluent-tutorials/aggregating-count/kstreams/)
* [Sum a stream of events](https://developer.confluent.io/confluent-tutorials/aggregating-sum/kstreams/)
* [Find the min/max](https://developer.confluent.io/confluent-tutorials/aggregating-minmax/ksql/)
* [Calculate a running average](https://developer.confluent.io/confluent-tutorials/aggregating-average/kstreams/)
* [Cogroup aggregates over multiple streams](https://developer.confluent.io/confluent-tutorials/cogrouping-streams/kstreams/)

### Joins

* [Join a KStream and a KTable](https://developer.confluent.io/confluent-tutorials/joining-stream-table/kstreams/)
* [Join a KStream and a GlobalKTable](https://developer.confluent.io/confluent-tutorials/joining-stream-global-ktable/kstreams/)
* [Join a KStream with another KStream](https://developer.confluent.io/confluent-tutorials/joining-stream-stream/ksql/)
* [Join a KTable with another KTable](https://developer.confluent.io/confluent-tutorials/joining-table-table/kstreams/)
* [Join two KTables with a foreign key](https://developer.confluent.io/confluent-tutorials/fk-joins/kstreams/)
* [Multi-join expressions](https://developer.confluent.io/confluent-tutorials/multi-joins/ksql/)
* [Versioned KTables for temporal join accuracy](https://developer.confluent.io/tutorials/versioned-ktables/kstreams.html)

### Windowing and time operations

* [Tumbling windows](https://developer.confluent.io/confluent-tutorials/tumbling-windows/kstreams/)
* [Sliding windows](https://developer.confluent.io/confluent-tutorials/sliding-windows/kstreams/)
* [Session windows](https://developer.confluent.io/confluent-tutorials/session-windows/kstreams/)
* [Emit a final result](https://developer.confluent.io/confluent-tutorials/window-final-result/kstreams/)

### Miscellaneous

* [Reprocess input topics](https://developer.confluent.io/confluent-tutorials/kafka-streams-application-reset/kstreams/)
* [Name stateful operations](https://developer.confluent.io/confluent-tutorials/naming-changelog-repartition-topics/kstreams/)
* [Schedule operations](https://developer.confluent.io/confluent-tutorials/kafka-streams-schedule-operations/kstreams/)
* [Expire data in a KTable with TTLs](https://developer.confluent.io/confluent-tutorials/schedule-ktable-ttl/kstreams/)
* [Expire data in a KTable created from aggregate()](https://developer.confluent.io/confluent-tutorials/schedule-ktable-ttl-aggregate/kstreams/)
* [Handle deserialization, processing, and production exceptions](https://developer.confluent.io/confluent-tutorials/kafka-streams-exception-handlers/kstreams/)
* [Handle uncaught exceptions](https://developer.confluent.io/confluent-tutorials/error-handling/kstreams/)

## Interactive Queries examples

As of Confluent Platform 3.1+ and Kafka 0.10.1+, you can query state stores created by the
[Kafka Streams DSL](developer-guide/dsl-api.md#streams-developer-guide-dsl) and the
[Processor API](developer-guide/processor-api.md#streams-developer-guide-processor-api).
For further information, see [Kafka Streams Interactive Queries for Confluent Platform](developer-guide/interactive-queries.md#streams-developer-guide-interactive-queries).

### Java

* [Word Count with Kafka Streams Interactive Queries](https://github.com/confluentinc/demo-scene/tree/master/kafka-streams-interactive-queries)

## Event-Driven Microservice example

### Java

The Event-Driven Microservice example implements an Order Service that provides
a REST interface to POST and GET orders. Posting an order creates an event in
Kafka, which is picked up by three different validation engines: a Fraud Service,
an Inventory Service, and an Order Details Service. These services validate the
order in parallel, emitting a PASS or FAIL based on whether each validation
succeeds.

* [Self-paced Kafka Streams tutorial based on the microservices example](microservices-orders.md#tutorial-microservices-orders): deployed in an event streaming platform with all the services in Confluent Platform and interconnecting other end systems

![Diagram of the event-driven microservices order-management example deployed across Confluent Platform services.](images/microservices-demo.png)

## Related content

- GitHub: [Confluent Code Tutorials](https://github.com/confluentinc/tutorials/)
- [Kafka Streams Data Types and Serialization](developer-guide/datatypes.md#streams-developer-guide-serdes)
- [Kafka Streams Domain Specific Language](developer-guide/dsl-api.md#streams-developer-guide-dsl)
- [Kafka Streams Processor API](developer-guide/processor-api.md#streams-developer-guide-processor-api)

#### NOTE
This website includes content developed at the [Apache Software Foundation](https://www.apache.org/)
under the terms of the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0.html).
