Skip to content

Commit

Permalink
DBZ-8666 Wasm SMT Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and Naros committed Feb 25, 2025
1 parent 363fac2 commit a5c3ff7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
9 changes: 8 additions & 1 deletion _data/authors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,11 @@ alvarvg:
bio: "Alvar is a Senior Software Quality Engineer at Red Hat. Passionate about bikes, games and software. He lives in Spain"
github: alvarvg
linkedin: alvarviana
avatar: alvarvg.png
avatar: alvarvg.png

andreatp:
name: "Andrea Peruffo"
bio: "With nearly two decades of coding experience, I'm fueled by passion as I continue to type away daily. As a Principal Software Engineer at Red Hat, I actively contribute to diverse Open Source projects, driven by both personal fulfillment and professional advancement. My not-so-secret passion lies in programming languages, developer tools, compilers, and beyond. Come and spot me on a project near you!"
github: andreaTP
twitter: and_prf
avatar: andreatp.png
95 changes: 95 additions & 0 deletions _posts/2025-02-24-go-smt.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
layout: post
title: Go SMT in Debezium
date: 2025-02-24 12:00:00 +0100
tags: [ debezium, smt, go, tinygo, chicory, WebAssembly, wasm ]
author: andreatp
---

Change Data Capture (CDC) is a cornerstone of modern cloud-native architectures, enabling real-time event-driven applications.
Debezium, a leading CDC platform, provides powerful Single Message Transformations (SMTs) to filter, route, and modify data streams before they reach their destination.

While Debezium is a Java-based project, many cloud-native applications are built in Go.
With this latest enhancement, you can now write SMT filters and routers in Go, allowing Go developers to fine-tune data processing within a Java technology thanks to https://tinygo.org/[TinyGo] and https://webassembly.org/[WebAssembly].

This blog post explores how to use Go plugins in Debezium, demonstrating how this feature enhances flexibility and customization for cloud-native teams.

+++<!-- more -->+++

== Go SMT Filters and Routers in Debezium

=== Introduction

Change Data Capture (CDC) is at the heart of modern event-driven architectures, enabling applications to react to database changes in real-time. Debezium has long provided a robust set of Single Message Transformations (SMTs) to filter, route, and modify events before they reach their final destination. But what if you wanted to extend Debezium's capabilities using a language other than Java?

With the latest enhancement, Debezium now allows developers to write SMT filters and routers in Go, opening up new possibilities for cloud-native applications. Since Go is widely used in cloud environments, this feature empowers teams to customize their CDC pipelines without leaving their primary development ecosystem.

== Why Go for SMTs?

Debezium runs on the JVM, and its SMTs have traditionally been Java-based, leveraging JSR 223.
While this is great for Java developers, who might want to write filters in Groovy or similar, many teams building cloud-native applications rely on Go. With this new feature, you can now:

- *Write SMT filters and routers in Go*, leveraging its simplicity, performance and type system.
- *Avoid Java dependency overhead* when Go is your primary language you don't need to add extra jars to the classpath.
- *Customize event processing logic* closer to your existing Go-based microservices.

This makes it easier for Go developers to fine-tune how change events are filtered and routed without needing Java expertise.

== How It Works

The integration is based on Go plugins, allowing Debezium to dynamically load and execute Go-based SMTs. These plugins act as lightweight, customizable event processors that filter and route CDC events before they reach Kafka or another downstream system.

Here's an example of how you can define a simple Go SMT filter:

[source,go,filter.go]
----
package main
import (
"github.com/debezium/debezium-smt-go-pdk"
)
// Example filter function
//export process
func process(proxyPtr uint32) uint32 {
var topicNamePtr = debezium.Get(proxyPtr, "topic")
var topicName = debezium.GetString(topicNamePtr)
return debezium.SetBool(topicName == "mytopic")
}
func main() {}
----

This function should to be compiled with https://tinygo.org/[TinyGo]:

[source,bash]
----
tinygo build -ldflags='-extldflags --import-memory' --no-debug -target=wasm-unknown -o filter.wasm filter.go
----

This function could be loaded as a plugin into Debezium, allowing the event processing pipeline to execute custom filtering logic in Go.
A sample configuration on how to achieve this looks as follows:

[source,none]
----
transforms=filter
transforms.filter.type=io.debezium.transforms.Filter
transforms.filter.language=wasm.chicory
transforms.filter.expression=file://filter.wasm
----

== Where This Fits Best

This feature is particularly useful for:

- *Cloud-native applications* where Go is already the dominant language.
- *Teams that want to extend Debezium without Java expertise.*
- *Environments with lightweight deployments*, where Go's efficiency and lazy access to the data can help keep resource usage low.

== A Glimpse into the Future

While this feature currently focuses on Go-based SMTs, it also hints at a broader trend: enabling Debezium users to bring their own languages to the CDC processing pipeline. WebAssembly (Wasm) could further extend this concept, allowing transformations to be written in a variety of languages while maintaining portability and security.
https://github.com/dylibso/chicory[Chicory] is being used as a zero dependencies Java Runtime for Wasm.

For now, if you’re working with Go-based cloud-native systems and want to fine-tune your CDC pipeline, this new capability in Debezium is an exciting step forward.
Binary file added assets/images/andreatp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5c3ff7

Please sign in to comment.