Zig NEWS

Cover image for Creating safer zig bindings for liburing
Vedant Pandey
Vedant Pandey

Posted on

Creating safer zig bindings for liburing

Last weekend I started on a hobby project to create a stock exchange from scratch.

On the quest I wanted to build everything from scratch and use zig, because I have wanted to build a deeper systems level understanding and it seems to give better warnings to problems a newbie might create.

The Project

The idea was to build a stock exchange while learning the fundamentals of how different internals work. I would start by using http(s) but I wanted to be able to replace the underlying protocol later if I wanted(with something like FIX)

Premature Optimization

I obviously wanted my hobby server to scale to millions of transactions so I wanted the best performance from the start, it was also a good moment for me to understand what io_uring truly is?

Enter IO Uring

What is even IO Uring?
I had heard some smart people mention IO Uring in their talks about performance optimization, one of them was obviously Joran Greef from TigerBeetle.

Ok, but what is io uring?
IO Uring is a kernal io module which came out in 2019, which offers an ability to blazingly fast IO by letting the kernel handle memory in its space instead of user space, and instead expose Ring Buffers for the user space application to interact with the sockets and file descriptors.

TBH, I have not fully understood IO Uring, or why exactly is it faster than epoll, but I'm hoping to learn that from building the safe bindings since I would need to go through hundreds of man pages

It also appears to be easy to get wrong for many skilled people, since Google has disabled it in every OS that it ships, because they held a VRP which caught majority of the vulnerabilities by using unsafely implemented io uring code.
Read more about it here

So, what is liburing?
At first I thought liburing and io_uring were the same, but it turns out liburing is a wrapper over io_uring to provide better defaults and an easier interface(comparatively I guess?) to interact with.

Using liburing

While using liburing in my project I found many difficulties setting it up. I was writing some glue code which would make it easier for me to understand the code flow. As I was going through it I thought to myself, there must be other people who would want to use liburing in their projects too, maybe someone would have written bindings?
To my surprise and happiness no one had done yet so I thought why don't I take this opportunity to build something that would not only help me learn but also help me give back to the community.

So here's my project github link, please feel free to create issues, but please know that I've only started and I mostly work on it on weekends(unless I get some time over the week)

https://github.com/vedant-pandey/liburing-zig

Top comments (0)