<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mark Gregan on Medium]]></title>
        <description><![CDATA[Stories by Mark Gregan on Medium]]></description>
        <link>https://medium.com/@mark_gregan?source=rss-1433146aaafb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7lQwVA8Mz6TsSZUT</url>
            <title>Stories by Mark Gregan on Medium</title>
            <link>https://medium.com/@mark_gregan?source=rss-1433146aaafb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:22:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mark_gregan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Configuring Streamdal with Terraform]]></title>
            <link>https://medium.com/streamdal/configuring-streamdal-with-terraform-d07e6cf9dfe3?source=rss-1433146aaafb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d07e6cf9dfe3</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[pipelines-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[pii-data]]></category>
            <dc:creator><![CDATA[Mark Gregan]]></dc:creator>
            <pubDate>Mon, 18 Mar 2024 18:11:02 GMT</pubDate>
            <atom:updated>2024-03-18T18:11:02.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*gPyLbsuuJhnelDGr4c0X2w.png" /></figure><p>We love our gorgeous UI and we know you will too. However, we understand that manually configuring all your pipelines can be a daunting task at scale. We’ve created a Terraform provider to help. This blog will show you how to quickly get a pipeline up and running with our Terraform provider.</p><h3><strong>Why Terraform?</strong></h3><p>As the current industry leader, Terraform was an obvious first choice of Infrastructure as Code (IaC) tooling to support configuring the Streamdal server. We do plan to support additional IaC tools in the future.</p><p>The Terraform provider and documentation can be found at: <a href="https://registry.terraform.io/providers/streamdal/streamdal/latest">https://registry.terraform.io/providers/streamdal/streamdal/latest</a></p><h3><strong>Getting Started</strong></h3><p><em>Skip this section if you are already familiar with Terraform and simply copy/paste the provider block below</em>.</p><ol><li><a href="https://developer.hashicorp.com/terraform/install">Install the Terraform command line tool</a></li><li>Create a directory/folder to hold the config file and Terraform data. Let’s call ours streamdal-config</li><li>Now create an empty text file called main.tf. This is where we’ll put the Streamdal pipeline definitions, written in <a href="https://github.com/hashicorp/hcl">Hashicorp Configuration Language(HCL)</a>.</li><li>In the main.tf file, we’ll configure a Terraform provider, which is used to take our HCL definitions and make the necessary API calls to the Streamdal Server:</li></ol><pre>terraform {<br>  required_providers {<br>    streamdal = {<br>      version = &quot;0.1.2&quot;<br>      source  = &quot;streamdal/streamdal&quot;<br>    }<br>  }<br>}<br><br>provider &quot;streamdal&quot; {<br>  token              = &quot;streamdal-server-token-here&quot;<br>  address            = &quot;streamdal-server-address-here:8082&quot;<br>  connection_timeout = 10<br>}</pre><p>5. Now run terraform init in your terminal to download the required provider. You should see output similar to the following:</p><figure><img alt="Results of the terraform init command" src="https://cdn-images-1.medium.com/max/836/1*fizDcFasK7RIVEEJ5uU_tg.png" /><figcaption>Output of Terraform init command</figcaption></figure><p>Now we’re ready to begin configuring our first pipeline and audience.</p><h3>Setting up our first Pipeline</h3><p>If you skipped the previous section, copy/paste the provider block into your .tf file.</p><p>We’ll start off with a basic pipeline definition that detects some PII (an email address) in a JSON payload and masks it.</p><p>We’ll use the <a href="https://registry.terraform.io/providers/streamdal/streamdal/latest/docs/resources/pipeline">pipeline resource</a> to configure this:</p><pre>resource &quot;streamdal_pipeline&quot; &quot;mask_email&quot; {<br>  name = &quot;Mask Email&quot;<br><br>  step {<br>    name = &quot;Detect Email Field&quot;<br><br>    # We specify abort conditions here since we don&#39;t want<br>    # to continue with the second step if there is nothing<br>    # to transform.<br>    on_false {<br>      abort = &quot;abort_current&quot; # No email found<br>    }<br>    on_error {<br>      abort = &quot;abort_current&quot; # An error occurred<br>    }<br>    dynamic = false<br>    detective {<br>      type   = &quot;pii_email&quot;<br>      args   = [] # no args for this type<br>      negate = false<br>      path   = &quot;&quot; # No path, we will scan the entire payload<br>    }<br>  }<br><br>  step {<br>    name    = &quot;Mask Email Step&quot;<br>    dynamic = true<br>    transform {<br>      mask_value {<br>        # No path needed since dynamic=true<br>        # We will use the results from the first detective step<br>        path = &quot;&quot;<br><br>        # Mask the email field(s) we find with asterisks<br>        mask = &quot;*&quot;<br>      }<br>    }<br>  }<br>}</pre><p>Using the streamdal_pipeline resource, we’ll configure a pipeline named <em>“Mask Email”</em>. This pipeline has two-step blocks that define each step of the pipeline.</p><p>The first step uses the <em>“Detective”</em> module (detective{})to look for email addresses (type=&quot;pii_email&quot;)anywhere in the JSON payload it receives.</p><p>This type of matcher does not require any arguments (args=[]), and by omitting a path to a specific field (path=&quot;&quot; ), the entire payload will be scanned for any fields that have a value of an email address.</p><p>Now on to the second step…</p><p>We define another step{} block to create a second step. The important bit here is dynamic=true which indicates that we will use the results from the first step.</p><p>We will mask the email in the JSON payload, using the <em>“Transform”</em> module ( transform{}). Inside the transform{} block, we’ll configure a mask_value transformation, with an empty path=&quot;”.</p><p><em>Note: We’re not specifying a path here because the previous step will pass any paths it detects as arguments to the second step.</em></p><p>Great! We’ve defined our first pipeline, and now we need to set up the “<a href="https://docs.streamdal.com/en/resources-support/glossary/#audience"><em>audience</em></a><em>”</em> to use this pipeline on.</p><h3>Defining and Assigning an Audience</h3><p>An <a href="https://docs.streamdal.com/en/resources-support/glossary/#audience"><em>audience</em></a> is a definition that the <a href="https://docs.streamdal.com/en/core-components/sdk/"><em>Streamdal SDK</em></a> uses to determine which pipelines to apply to a given call to .Process() . It consists of 4 pieces of data:</p><ul><li>service_name — A name indicating the service you’re running the SDK in.</li><li>component_name —This is used to indicate the source or destination of the data that you will be processing. Typically something like kafka , postgres , rabbitmq , etc</li><li>operation_name — Some kind of short descriptor indicating the operation that is processing the data.</li><li>operation_type — Either consumer or producer</li></ul><p>For demo purposes, let’s say we’re running the <a href="https://docs.streamdal.com/en/core-components/sdk/"><em>Streamdal SDK</em></a> in our <strong>billing service</strong>, which <strong>consumes</strong> data from a <strong>Kafka</strong> topic in order to generate a <strong>sales report</strong>.</p><p>Using the streamdal_audience Terraform resource, we would define the audience as follows:</p><pre>resource &quot;streamdal_audience&quot; &quot;billing_sales_report&quot; {<br>  service_name   = &quot;billing-svc&quot;<br>  component_name = &quot;kafka&quot;<br>  operation_name = &quot;gen-sales-report&quot;<br>  operation_type = &quot;consumer&quot;<br>  pipeline_ids   = [resource.streamdal_pipeline.mask_email.id]<br>}</pre><p>For folks unfamiliar with Terraform, the value of the pipeline_ids field is dynamically populated by the result of the streamdal_pipeline resource we previously defined.</p><p>Now save your main.tffile, and we’ll create our pipeline and audience in the Streamdal server with the terraform apply command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*YjofweyEhhBqHo1eUR0Jmg.png" /><figcaption>Output from Terraform apply command</figcaption></figure><p>Let’s open up our Streamdal console to see the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haniZxTwPMpgQAi46cizvw.png" /><figcaption>Streamdal console with our new pipeline and audience</figcaption></figure><p>As you can see, our <a href="https://docs.streamdal.com/en/resources-support/glossary/#audience"><em>audience</em></a> is now defined and the “Mask Email” pipeline has been created and assigned to it.</p><p><strong>We’re now ready to process data through our pipeline and prevent PII leakage!</strong></p><h3>Full Example</h3><p>We have created a repository located at <a href="https://github.com/streamdal/blog-terraform-demo">https://github.com/streamdal/blog-terraform-demo</a> with the Terraform code from this article and also an example Golang app for you to run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_qEuXucw8esN0hNUYPD2g.png" /><figcaption><a href="https://discord.gg/streamdal">discord.gg/streamdal</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d07e6cf9dfe3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streamdal/configuring-streamdal-with-terraform-d07e6cf9dfe3">Configuring Streamdal with Terraform</a> was originally published in <a href="https://medium.com/streamdal">Streamdal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protobuf vs JSON for Your Event-Driven Architecture]]></title>
            <link>https://medium.com/streamdal/protobuf-vs-json-for-your-event-driven-architecture-6c7c4464289b?source=rss-1433146aaafb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c7c4464289b</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[protobuf]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Mark Gregan]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 14:02:22 GMT</pubDate>
            <atom:updated>2024-01-26T17:13:08.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ocwgsfZJjIwTzAvPLPPzHg.png" /><figcaption>Join me on Discord: <a href="https://discord.gg/streamdal">discord.gg/streamdal</a></figcaption></figure><p>Choosing a serialization method for your data can be a confusing task considering the multitude of options out there, such as JSON, MessagePack, AVRO, Thrift, Protobuf, Flat Buffers, etc. If you’re using gRPC or Thrift RPC to communicate between your services, the decision has already been made for you. But for event-driven, you’ll more than likely want to prioritize performance over other considerations.</p><p>Today we’ll evaluate two of the most common serialization methods for event-driven systems: Protocol Buffers and JSON. Let’s briefly overview both options:</p><h3>Protobuf vs JSON: A Quick Overview</h3><h4>JSON</h4><p>JSON is probably the most obvious candidate for most:</p><ul><li>Supported in the standard library of almost any language.</li><li>Human-readable.</li><li>No strict schema to deal with.</li></ul><p>Due to its ubiquity, dealing with JSON is going to be the easiest option. Even better, you don’t need any tooling to see what’s in the messages. Just pop open kafdrop web UI and view your messages in plain text, easy-peasy! Depending on your needs and/or point-of-view, the lack of a strictly defined schema can be a positive or a negative. We’ll discuss that further later on.</p><h4>Protobuf</h4><p>Protobuf is the less obvious choice of the two. But it definitely has its strengths:</p><ul><li>Schemas for free</li><li>Support for binary fields without the need to base64 back and forth</li><li>Built-in API support with gRPC</li><li>And most importantly: Speed!</li></ul><p>There is a bit of initial setup work when dealing with protobuf:</p><ol><li>First, you have to define your events and their schemas ahead of time.</li><li>Then you have to use protoc, which isn&#39;t the world&#39;s most intuitive tool, to generate the code needed to create/manipulate protobuf events.</li><li>And finally, you have to include that generated code in all of your projects that are handling your events.</li></ol><p>That’s a few more steps than just calling <a href="https://pkg.go.dev/encoding/json#Marshal">[json.Marshal()]</a>and <a href="https://pkg.go.dev/encoding/json#Unmarshal">[json.Unmarshal()]</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*opJR8FKIon2EVCRxkvjczw.png" /><figcaption>Visit <a href="https://demo.streamdal.com/">demo.streamdal.com</a></figcaption></figure><h3>Protobuf vs JSON: Schemas</h3><h4>Do I even need a Schema?</h4><p>Plain JSON is definitely going to be easier and quicker to iterate with. You won’t have to update any definitions, regenerate any code, or re-pull any changes into your code bases. Need a new field? Just add it in service A, and update service B to read the new field.</p><p>We can see that this is probably not going to scale well, however. Having multiple engineers on multiple teams adding, removing, or editing fields at will is going to result in things breaking at some point. It would be much better to have a single source of truth, a clearly defined schema.</p><h4>Schema Options for JSON</h4><p>The two big players in codifying the schema of a JSON message are <a href="https://avro.apache.org/">AVRO</a> and <a href="https://json-schema.org/">JSONSchema</a>. The specifics/benefits of these two are outside the scope of this discussion, but we’re including them to let you know that there are options out there.</p><h4>Schema Options for Protobuf</h4><p>Here’s a key benefit of using protobuf, the definitions already define the schemas. No need to layer any other solution on top!</p><p>There are some caveats to be aware of though. Changing the type on a field will break backward compatibility, preventing you from replaying or reading messages generated before the change. It’s best to treat protobuf definitions as additive only. If your field’s data type needs to change, add a new field with the new data type, and “remove” the old field by marking it as deprecated (by appending [deprecated = true ] to the end of the field definition), or reserving the field number.</p><h3>Protobuf vs JSON: Performance</h3><p>If you’re going the event-driven architecture route, you’re probably interested in scale and want the best performance you can get out of a serialization method.</p><p>Let’s write some benchmarks to get an idea of the speed of both. At Streamdal, we’re a Golang shop, so we’ll use that for our benchmark. If you’re using a different language, its implementations of JSON and protobuf and the resulting performance will be different.</p><p>First, we’ll define both the JSON and protobuf events. Our JSON event will look like this:</p><pre>type MyJSONMessage struct {<br>	Id      string `json:&quot;id&quot;`<br>	Message string `json:&quot;message&quot;`<br>	Num     int    `json:&quot;num&quot;`<br>}</pre><p>And our protobuf event will look like this:</p><p><em>events/mypbmessage.proto:</em></p><pre>syntax = &quot;proto3&quot;;</pre><pre>package events;</pre><pre>option go_package = &quot;github.com/streamdal/pbvsjson/events&quot;;</pre><pre>messageMyPBMessage {<br>  string id = 1;<br>  stringmessage = 2;<br>int32 num =</pre><p>We’ll compile that proto definition into Go code:</p><pre>$ protoc -I ./events --go_out=paths=source_relative:events events/*.proto</pre><p>Now let’s benchmark serializing and deserializing our JSON and protobuf events:</p><p><em>main_test.go:</em></p><pre>package main</pre><pre>import (<br>	&quot;encoding/json&quot;<br>	&quot;math&quot;<br>	&quot;testing&quot;<br>	&quot;github.com/golang/protobuf/proto&quot;<br>	&quot;github.com/streamdal/pbvsjson/events&quot;<br>)</pre><pre>type MyJSONMessagestruct {<br>	Idstring `json:&quot;id&quot;`<br>	Messagestring `json:&quot;message&quot;`<br>	Numint    `json:&quot;num&quot;`<br>}</pre><pre>var msg *MyJSONMessage<br>var pbMsg *events.MyPBMessage</pre><pre>funcinit() {<br>	msg = &amp;MyJSONMessage{<br>		Id:      &quot;97ec560f-2b14-4930-9a27-f0427f08951c&quot;,<br>		Message: &quot;Let&#39;s benchmark!&quot;,<br>		Num:     math.MaxInt32,<br>	}</pre><pre>	pbMsg = &amp;events.MyPBMessage{<br>		Id:      &quot;97ec560f-2b14-4930-9a27-f0427f08951c&quot;,<br>		Message: &quot;Let&#39;s benchmark!&quot;,<br>		Num:     math.MaxInt32,<br>	}<br>}</pre><pre>funcBenchmarkJSON(b *testing.B) {<br>for i := 0; i &lt; b.N; i++ {<br>		// First marshal to JSON<br>		data, err := json.Marshal(msg)<br>if err != nil {<br>			b.Error(err)<br>		}</pre><pre>		// Now unmarshal back into usable struct<br>		decoded := &amp;MyJSONMessage{}<br>if err := json.Unmarshal(data, decoded); err != nil {<br>			b.Error(err)<br>		}<br>	}<br>}</pre><pre>funcBenchmarkProtobuf(b *testing.B) {<br>for i := 0; i &lt; b.N; i++ {<br>		// First marshal to wire format<br>		data, err := proto.Marshal(pbMsg)<br>if err != nil {<br>			b.Error(err)<br>		}</pre><pre>		// Now unmarshal back into usable struct<br>		tmpMsg := &amp;events.MyPBMessage{}<br>if err := proto.Unmarshal(data, tmpMsg); err != nil {<br>			b.Error(err</pre><p>And let’s see what those benchmarks look like:</p><pre>$ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/streamdal/pbvsjson<br>cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz<br>BenchmarkJSON-8                 	  612400	      1731 ns/op<br>BenchmarkProtobuf-8             	 3088689	       385.9 ns/op</pre><p><strong><em>Protobuf is the clear winner here.</em></strong></p><p>Let’s dig a little deeper and see why with some more benchmarks:</p><p><em>main_test.go:</em></p><pre>funcBenchmarkJSON_marshal(b *testing.B) {<br>for i := 0; i &lt; b.N; i++ {<br>		// First marshal to JSON<br>		_, err := json.Marshal(msg)<br>if err != nil {<br>			b.Error(err)<br>		}<br>	}<br>}</pre><pre>funcBenchmarkProtobuf_marshal(b *testing.B) {<br>for i := 0; i &lt; b.N; i++ {<br>		// First marshal to wire format<br>		_, err := proto.Marshal(pbMsg)<br>if err != nil {<br>			b.Error(err)<br>		}<br>	}<br>}</pre><pre>funcBenchmarkJSON_unmarshal(b *testing.B) {<br>	data, err := json.Marshal(msg)<br>if err != nil {<br>		b.Error(err)<br>	}</pre><pre>for i := 0; i &lt; b.N; i++ {<br>		tmpMsg := &amp;MyJSONMessage{}<br>if err := json.Unmarshal(data, tmpMsg); err != nil {<br>			b.Error(err)<br>		}<br>	}<br>}</pre><pre>funcBenchmarkProtobuf_unmarshal(b *testing.B) {<br>	data, err := proto.Marshal(pbMsg)<br>if err != nil {<br>		b.Error(err)<br>	}</pre><pre>for i := 0; i &lt; b.N; i++ {<br>		tmpMsg := &amp;events.MyPBMessage{}<br>if err := proto.Unmarshal(data, tmpMsg); err != nil {<br>			b.Error(err)<br>		}</pre><p>These additional benchmarks give us:</p><pre>$ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/streamdal/pbvsjson<br>cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz<br>BenchmarkJSON-8                 	  612400	      1731 ns/op<br>BenchmarkProtobuf-8             	 3088689	       385.9 ns/op<br>BenchmarkJSON_marshal-8         	 3975855	       302.7 ns/op<br>BenchmarkProtobuf_marshal-8     	 8163854	       145.1 ns/op<br>BenchmarkJSON_unmarshal-8       	  886795	      1290 ns/op<br>BenchmarkProtobuf_unmarshal-8   	 5829130	       217.1 ns/op</pre><p>A 2x advantage when serializing Protobuf vs JSON. Not bad! But the real win here is when unserializing. The overhead of having to parse the text-based JSON format is too insignificant not to ignore. At a 6x speed advantage, protobuf is the way to go for the performance-minded.</p><h3>Protobuf vs JSON: Message Size</h3><p>The JSON message clocks in at 91 bytes, and the protobuf message at 62 bytes. Our example events are trivial in structure for the sake of grok-ability, but your events will grow along with the number transmitted through your infrastructure. Size should be a consideration.</p><h3>Protobuf vs JSON: Observability &amp; Readability</h3><p>As a text-based format, JSON wins the readability challenge. That’s not to say Protobuf can’t be made readable though. Whether you build a tool internally or use an open-source tool like <a href="https://github.com/streamdal/plumber">Plumber</a>.</p><h3>Conclusions</h3><p>In the world of scale, protobuf is definitely the way to go.</p><p>Schemas are a great benefit to microservice architecture by giving you a single source of truth for how your events should be structured. It may seem like a bunch of busy work in the beginning, but the benefits lay at scale.</p><p>Observability takes a hit when it comes to protobuf, but there are solutions.</p><p>For hobby projects, JSON is a solid choice for readability and development velocity. But in the world of scale, go binary, go protobuf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YipImrF86Enhx-c3Z9tHwg.png" /><figcaption><a href="https://discord.gg/streamdal">discord.gg/streamdal</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c7c4464289b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streamdal/protobuf-vs-json-for-your-event-driven-architecture-6c7c4464289b">Protobuf vs JSON for Your Event-Driven Architecture</a> was originally published in <a href="https://medium.com/streamdal">Streamdal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>