---
title: "Build a Real-time Materialized View from Postgres Changes using Confluent’s ksqlDB"
description: "Postgres logical replication can feed a Debezium-based CDC connector on Confluent Cloud that streams changes from Neon tables into Kafka topics, where ksqlDB aggregates them into a continuously updated materialized view."
url: "https://swe.quest/articles/build-a-real-time-materialized-view-from-postgres-changes-using-confluent-s-cfa507d6c7070e59"
canonical: "https://neon.com/blog/real-time-materialized-view-postgres-kafka-ksqldb"
source: "Neon"
published: "2024-02-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["event-driven","postgres","stream-processing","messaging"]
---

# Build a Real-time Materialized View from Postgres Changes using Confluent’s ksqlDB

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-02-28, 10 min read, How-to. Original: [https://neon.com/blog/real-time-materialized-view-postgres-kafka-ksqldb](https://neon.com/blog/real-time-materialized-view-postgres-kafka-ksqldb)

## Summary

Postgres logical replication can feed a Debezium-based CDC connector on Confluent Cloud that streams changes from Neon tables into Kafka topics, where ksqlDB aggregates them into a continuously updated materialized view. The walkthrough builds a player leaderboard: create a publication and pgoutput replication slot, configure the Postgres CDC Source connector with JSON\_SR schemas, import topics as ksqlDB streams, and define a SUM aggregation table with EMIT CHANGES. Compared with Postgres REFRESH MATERIALIZED VIEW, this approach avoids repeated refresh costs, retains history in Kafka, and pushes updates to subscribers via the ksqlDB REST API.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Event-driven architecture](https://swe.quest/tags/event-driven.md) (Backend & APIs)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Stream processing](https://swe.quest/tags/stream-processing.md) (Data & databases)
- [Queues & messaging](https://swe.quest/tags/messaging.md) (Backend & APIs)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Apache Kafka topics and partitions ([easy posts on Queues & messaging](https://swe.quest/tags/messaging.md?difficulty=easy))
- SQL aggregations ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

ksqlDB, Apache Kafka, Debezium, Confluent Cloud, Neon, Kafka Connect, logical replication, Schema Registry

## Related posts

- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 2](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-2-2123f803752f2e9d.md): ClickHouse · 2023-06-15 · Medium · 22 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Data pipelines, Replication
  A Postgres-to-ClickHouse CDC pipeline is built with Debezium, Kafka Connect and a ClickHouse materialized view, keeping a ReplacingMergeTree table in sync with the 28M-row UK property price dataset under a mix of inserts, updates and deletes.
- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-1-10e3d601e2748dab.md): ClickHouse · 2023-06-15 · Medium · 23 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Replication, Queues & messaging
  Postgres-to-ClickHouse CDC can be built by streaming row changes from Postgres logical decoding (pgoutput plugin, replication slots, LSN ordering) through Debezium and Kafka, then applying them in ClickHouse with the ReplacingMergeTree engine.
- [Chaining Materialized Views in ClickHouse](https://swe.quest/articles/chaining-materialized-views-in-clickhouse-79c630686e93ebe9.md): ClickHouse · 2024-04-16 · Medium · 8 min read · Analytics & OLAP, Stream processing, SQL
  ClickHouse materialized views can be chained so that one view reads from a table populated by another, rather than having several views all read from the same Kafka engine table.
- [Change Data Capture with Neon and Materialize](https://swe.quest/articles/change-data-capture-with-neon-and-materialize-b7e8c6b1f01b6525.md): Neon · 2023-12-21 · Medium · 4 min read · Event-driven architecture, PostgreSQL, Replication, Stream processing
  Neon's logical replication support lets Materialize ingest Postgres changes directly via the native replication protocol, without Debezium or other extra infrastructure, while keeping transactional consistency.
- [“Just OLAP it”: How Ramp rebuilt its analytics platform on ClickHouse Cloud](https://swe.quest/articles/just-olap-it-how-ramp-rebuilt-its-analytics-platform-on-clickhouse-cloud-36298842faab88cc.md): ClickHouse · 2026-01-20 · Medium · 5 min read · Analytics & OLAP, Event-driven architecture, Data pipelines, PostgreSQL, Queues & messaging
  Ramp moved customer-facing spend analytics off its Postgres monolith after enterprise customers' reports on a single card-transactions table began taking 40+ seconds, and now serves them in milliseconds from ClickHouse Cloud.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
