Running ksqlDB (KSQL) with AWS MSK
Codemia Knowledge Hub ·
Amazon MSK does not include KSQL, but you can run KSQL (now ksqlDB, part of the Confluent Platform) yourself and point it at the MSK brokers. MSK runs the Kafka cluster as a managed service, and ksqlDB adds a streaming SQL engine for processing the data in real time.
What ksqlDB is
ksqlDB is an open-source stream processing framework that uses SQL-like syntax to read, write and process streaming data in Kafka. It supports stream processing operations, aggregation, joins and windowing.
Its main features:
- Stream processing in SQL: complex processing logic is written in familiar SQL syntax, so developers with SQL skills can pick it up quickly.
- Event-time processing: streams are processed based on when events actually occurred, not only when they are processed.
- Interactive queries: you can run queries against streams and tables to get real-time results.
- Materialized views: ksqlDB creates materialized views that update continuously as new data arrives, so queries stay fast.
Connecting ksqlDB to an MSK cluster
You run Confluent's ksqlDB service yourself and configure it to talk to the Kafka cluster that MSK manages:
- Set up Amazon MSK: launch an MSK cluster, choosing the Apache Kafka version, cluster configuration and node size for your workload.
- Configure Kafka Connect: deploy Kafka Connect, which connects ksqlDB to other data sources and sinks.
- Deploy ksqlDB: run ksqlDB servers on their own or as part of the Confluent Platform, on EC2 instances or in containers on Amazon ECS or EKS.
- Connect ksqlDB to MSK: configure ksqlDB with the broker endpoints of the MSK cluster so it can consume and produce messages.
Example: aggregating a transaction stream
For a real-time analytics case with a high-throughput event stream, you can define a stream over a topic and aggregate it in hourly windows:
Sizing and network latency
Give the ksqlDB servers enough memory and CPU, and configure the network carefully so they have low-latency access to the MSK brokers.
What each side contributes
| Feature | Description | AWS MSK Integration |
| Real-time processing | Processes data as it arrives, in real time. | Connects to MSK for real-time data streaming. |
| SQL-like syntax | Enables stream processing using familiar SQL-like queries. | Use SQL skills without needing proprietary tech knowledge. |
| Scalability | Scales horizontally by adding more nodes. | MSK manages the Kafka cluster scaling automatically. |
| Interactive Queries | Queries data streams interactively. | MSK supports various consumer configurations for optimized query performance. |
Related reading
- KSQL streams - Get data from Array of Struct
- KSQL table not showing data but Stream with same structure returning data
- KSQL Windowed Aggregation Stream
- KStream batch process windows
- kubectl apply vs kubectl create?
- Kubernetes - how to tear down cluster?
- KTable-KTable foreign-key join not producing all messages when topics have more than one partition
- KTable state store infinite retention
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.