Imagine you are streaming changes from Postgres to Elasticsearch in Go

Arpit Bhayani

Arpit Bhayani

Dec 12, 2025 • 2 min read


Imagine you are streaming changes from Postgres to Elasticsearch in Go. Everything works fine in dev. Then traffic ramps up, and suddenly your service can’t keep up…

After profiling, you notice the bottleneck: JSON serialization.

Every document going to Elasticsearch needs to be encoded. At thousands of events per second, those microseconds add up fast. Go’s standard encoding/json library is convenient, but it heavily relies on reflection.

Reflection is flexible, but that flexibility has a cost - it’s slower than having the structure known at compile time.

And remember, there is never just one lib to do something in a language. People keep building and rebuilding things, often making them faster than what ships by default.

So instead of relying on the standard encoding/json, there is a Go package jsoniter. In that, decoding a medium payload takes 35,510 ns/op with 99 allocations using the standard library. jsoniter does it in 5,623 ns/op with just 3 allocations. Over 6x faster with 97% fewer allocations.

Insane.

This doesn’t mean you should immediately rewrite your code. But if you ever find JSON serialization sitting at the top of your flame graph :) switching to jsoniter or whatever is most efficient at that time can save you a lot of pain.

Btw, you will find something similar in every language for every kind of work. Use this post as a reminder to look beyond default :)

Hope this helps.

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses