Kafka Go client: No Producer error during connection ?

Although its rare, but there are times when you actually want to see errors in your code – more importantly, at the right time !

Kafka Go Producer behaviour

You need to be mindful of this while using the Kafka Go client producer. For e.g. if you were to supply an incorrect value for the Kafka broker …

no error

… assuming you don’t have a Kafka broker at foo:9092, you would expect that the above code will respond with producer creation failed along with the specific error details. Instead, the flow carries on and ends by printing done. This is because the error returned by Produce is only in case message does not get enqueued to the internal librdkafka queue

You should…

Hook up to the delivery producer reports channel (using Producer.Events()) in order to catch this error – better late than never right !

Now, the error is rightfully returned – producer error foo:9092/bootstrap: Failed to resolve 'foo:9092': nodename nor servname provided, or not known (after 1543569582778ms in state INIT)

You can also provide your own channel to the Produce method to receive delivery events. Only the error is handled and the other possible event i.e. *kafka.Message is ignored under the default case umbrella



Posted in Distributed systems, go, Kafka, messaging | Tagged , , | Leave a comment

Kafka Go client quick start

Here is a Docker based example for Kafka using Go client


  • Producer
    • uses the traditional API for pushing messages to Kafka (channel is another option)
    • receives notifications on the (default) Events (custom channel is another option or you can choose not to get notified)
  • Consumer uses (Events) channel – Poll()ing is another alternative
  • Docker Compose to bootstrap the sample app (producer and consumer) as a single unit
  • BYOK (bring your own Kafka) for trying this out

To run

Check out the README – it’s super easy to get going, thanks to Docker Compose!




Posted in Distributed systems, Kafka, messaging | Leave a comment

Redis 5 – bootstrapping a Redis Cluster with Docker

With Redis 5 (in RC state at time of writing), cluster creation utility is now available as part of redis-cli which is easier as compared to the (previous) ruby way of doing it (using redis-trib)

check out the release notes for more info

Here is the command list – docker run -i --rm redis:5.0-rc redis-cli --cluster help


redis-cli –cluster help

It’s super simple to create a 6-node Redis Cluster (3 masters and corresponding slaves) on Docker

Once executed, you should see a similar output

To check cluster, you can run

  • ​​​​​docker run -i --rm --net redis_cluster_net redis:5.0-rc redis-cli --cluster check localhost:6380
  • docker run -i --rm --net redis_cluster_net redis:5.0-rc redis-cli --cluster info localhost:6380


Posted in Distributed systems, nosql, redis | Tagged , , , , | 6 Comments

(eBook) Practical Redis: first few chapters released!

I am happy to announce that the first few chapters of Practical Redis are now available

About Practical Redis



It is a hands-on, code-driven guide to Redis where each chapter is based on an application (simple to medium complexity) which demonstrates the usage of Redis and its capabilities (data structures, commands etc.).

The applications in the book are based on Java and Golang. The Java based Redis client libraries which have been used in this book include JedisRedisson and Lettuce while go-redis is used as the client library for Golang. Docker and Docker Compose are used to deploy the application stack (along with Redis)


Here is a quick outline of the book contents

  • Hello Redis – quick tour of Redis capabilities including its versatile data structures
  • Redis: the basic data structures – intro to core Redis data structures with a Java based news sharing app using the Jedisclient
  • Extending Redis with Redis Modules – learn about the basics of Redis Modules and make use of ReBloom in a Go based recommendation service
  • Tweet analysis service – keep track of relevant tweets using a Java and Go based application which ingests tweets, consumes/processes them and produces queryable info in real time using reliable queues (Redis LISTs), SETs and HASHes

Coming soon …

The below chapters are work in progress on and will be made available in subsequent releases of this book

  • Pipelines and Transactions in Redis
  • Scalable chat application – Use Redis PubSub and Websocket to create a chat service
  • Stream processing with Redis – watch Redis Streams in action (new data structure in Redis 5.0)
  • Redis based Tracking service – thanks to combination of the Geo data type and Lua scripting capability in Redis
  • Redis for distributed computing – explore interesting use cases made possible by Redisson
  • Data partitioning in Redis – practical examples highlighting data sharding strategies in Redis
  • Redis high availability

Go check it out & stay tuned for more updates


Posted in Distributed systems, go, nosql, redis | Tagged , , , , , , , , | Leave a comment

Redis geo.lua example using Go

I stumbled upon geo.lua which seemed to be an interesting library

It’s described as – “… a Lua library containing miscellaneous geospatial helper routines for use with Redis

Here is an example of using it with the Go Redis client (go-redis). This is what it does in a nutshell

To run, refer README – its super simple


Posted in go, nosql, redis | Tagged , , , , , , | Leave a comment

certificate error with Go HTTP client in alpine Docker

Using the Go HTTP client from a alpine docker image will result in this error – x509: failed to load system roots and no roots provided

Solution: alpine is a minimal image, hence CA certificates are required. You add that in the Dockerfile as per below example

FROM alpine 
RUN apk add --no-cache ca-certificates 
COPY my-app .
CMD ["./my-app"]

Got this hint from the golang alpine Dockerfile
Posted in go | Tagged , , , | Leave a comment

etcd Watch example using Go client

etcd is a distributed, highly available key-value store which serves as the persistent back end for Kubernetes


Here is an example to demonstrate its Watch feature. For details, check out the README (and the sample code) on Github

It uses



Posted in Distributed systems | Tagged , , , | Leave a comment

NATS on Kubernetes example

In a previous blog, you saw an example of NATS along with producer and consumer – based on Docker Compose. This post uses the same app, but runs on Kubernetes


For how to run, follow the README on Github

High level overview

  • uses the NATS Kubernetes operator
    • it seeds a CRD …
    • … using which we can spawn a NATS cluster on Kubernetes (with a single command!)
    • A Service object is created automatically – uses ClusterIP by default


NATS Kubernetes Service object

  • The environment variable corresponding to the Serviceis used in the application logic to locate NATS server. Note its usage here



Posted in Distributed systems, Kubernetes, nats | Tagged , , , , , , , , | Leave a comment

Redis tech tip #1

In order to delete members from your Redis Geo-spatial collection, you can use ZREM (underneath the hood, the data is stored in a sorted set)

Add a few (Indian) cities

GEOADD IndianCities 28.6108127 77.2060241 NewDelhi

​GEOADD IndianCities 12.9715987 77.5945627 Bangalore

GEOADD IndianCities 13.0826802 80.2707184 Chennai

The weather in Chennai humid – not my kind.. let’s remove it

ZREM IndianCities Chennai

You can also delete the entire collection using DEL IndianCities (usual stuff…)


Posted in nosql, redis | Tagged , , , | Leave a comment

NATS & Kafka: random notes

This is not NATS vs Kafka by any means – just jotting down some info. NATS recently joined CNCF (which host projects like Kubernetes, Prometheus etc. – look at the dominance of Golang here!) and that’s when it caught my attention

I have been taken aback by its simplicity and performance (yet to test drive it fully – but the numbers are out there)

  • Kafka runs on JVM (Scala to be specific), NATS is written in Go
  • Protocol – Kafka is binary over TCP as opposed to NATS being simple text (also over TCP)
  • Messaging patterns – Both support pub-sub and queues, but NATS supports request-reply as well (sync and async)
  • For (horizontally) scalable processing,
    • NATS has a concept of queue (with a unique name of course) and all the subscribers hooked on same queue end up being a part of the same queue group. Only one of the (potentially multiple) subscribers gets the message. Multiple such queue groups would also receive the same set of messages. This makes it a hybrid pub-sub (one-to-many) and queue (point-to-point)
    • Same thing is supported in Kafka via consumer groups​ which can pull data from one or more topics
  • Stream processing – NATS does not support stream processing as a first class feature like Kafka does with Kafka Streams
  • Kafka clients use a poll-based technique in order to extract messages as opposed to NATS where the server itself routes messages to clients (maintains an interest-graph internally)
  • NATS can act pretty sensitive in the sense that it has the ability to cut off consumers who are not keeping pace with the rate of production as well as clients who don’t respond to heartbeat requests.
    • The consumer liveness check is executed by Kafka as well. From what I recall, this is done/initiated from the client itself & there are complex situations that can arise due to this (e.g. when you’re in a message processing loop and don’t poll ). There are a bunch of configuration parameter/knobs to tune this behavior (on client side)
  • Delivery semantic – NATS supports at-most once (and at-least-once with NATS streaming) as opposed to Kafka which also supports exactly-once (tough!)
  • NATS doesn’t seem to have a notion of partitioning/sharding messages like Kafka does
  • No external dependency in case of NATS. Kafka requires Zookeeper

… work in progress…


Posted in Distributed systems, Kafka, messaging | Tagged , , , | Leave a comment