mustela

mustela

Best way to persist events in kafka

Hey everyone!

I’m wondering if I could get some insight on how people are doing the following.
The flow is simple, and I’m sure there are a lot of people already doing it, but I need to expose an endpoint, let’s say POST events (authentication/authorization will also happen in here) where other services can send events :slight_smile: , those events should be persisted into kafka, and then consumed by elixir/broadway to do some data manipulation and other stuff.

The part that I’m curious about is how to send those events to kafka. I was hoping to use Broadway to manage it too, and make use of all the features it provides, but to do this I would have to implement some kind of intermedia storage, to put those http events, and being able to read them using a custom producer (I couldn’t find any other way).

I’m trying to simplify the complexity and underlying technology between the http event and kafka, but without losing control and “supervision” of those events.

Appreciate you all for any kind of input you could provide!

Thanks a lot!

First Post!

dimitarvp

dimitarvp

That’s a really good question but it highly depends on a few factors:

  • Do you want data types to be strict for each field?
  • Do you want optional fields or is every field mandatory?
  • Do you want zero-copy? This means that there is no serialize / unserialize stages: when you get a byte array buffer it can directly be iterated over and read without having to convert it to an in-memory structure.
  • Do you want future extensibility without old clients breaking?
  • Do you mind having a schema known beforehand?

I’ve been studying data formats lately and to be fair, I can only recommend Google’s FlatBuffers, Ethereum’s RLP (only a byte array encoding though, no concept of types) or maybe MessagePack (although that has the ser/deser stage).

Additionally, a very simplified ASN.1 format that gets ser/deser in BER or DER formats can be very viable and easy to do – but honestly, don’t go down the ASN.1 rabbit hole. You’ve been warned.

Looking through Comparison of data-serialization formats in Wikipedia only shows me one more good candidate – Binn – but haven’t evaluated it yet. Check out that page, it’s not a bad comparison (probably lacking good other formats I’d presume).

Seeing your post’s loosely defined requirements I’d not go for FlatBuffers even though I think it’s a good fit for many scenarios. For your case JSON/BSON might be the least painful option.

Or simply Erlang’s ETF format? (Check out :erlang.binary_to_term and :erlang:term_to_binary)

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement