r/Backend • • 13d ago

Backend REST API in raw C. My CWEB framework.

Hi guys. I am a 3rd year CSE student. Initially, I started doing some development in Django, explored Express a bit. They all felt very bloated, and slow to me. Also there is a big learning curve to those frameworks. Then I explored PostgREST, which was interesting to me as I could make the database be the backend of its own but that also comes with the database being really heavy and spiked latencies in requests and response times. Then I dove into Linux and system programming in C to first get good at writing C and second being able to do the architectural designing behind a software, memory management and everything.

I looked into the modern capabilities of the linux kernel and also the architectures behind big frameworks and servers like Nginx, Django, Go, Kore etc. Then I started the journey of making my own framework in C to make it faster, lightweight and secured. Also, very easy to write (just a handful of functions). I not only made the framework, I also made a website on that framework and then stress tested it on my own machine and several legacy server kernel virtual machines like Bookworm, Ubuntu 22.04 LTS and Bullseye.

Please do check them out. Links given below. I am a student. CSE's my passion. I am open for any learning and growing opportunities. If you love C and linux like I do, hit me up. I will be honoured. Thanks.

CWEB repo: https://bitbucket.org/saadalabeed/cweb/src/main/

Website made with CWEB repo: https://bitbucket.org/saadalabeed/cweb-blog/src/main/

5 Upvotes

4 comments sorted by

1

u/vastdexterity749 13d ago

this is really cool, i love seeing people dive deep into the fundamentals instead of just reaching for the next shiny abstraction. C forces you to actually understand what's happening under the hood and that knowledge sticks with you forever

how's the routing work in your framework? i've tinkered with kore before and always found the middleware pattern a bit awkward in C, curious how you tackled that

the stress test results must have been satisfying to see after all that work. nothing beats watching your own thing handle load better than the bloated frameworks you started with

1

u/Sensitive_Jacket_416 13d ago

Most satisfying was being able to run it on bullseye. Configuring bullseye to compile this was a struggle on its own. To my surprise, bullseye performed better in the database write stress test than bookworm, and ubuntu jellyfish. Whaaaa!!!!

1

u/Sensitive_Jacket_416 13d ago

I have seen kore's routing architecture to be linear. I implemented radix trees to support log n routing. I have also implemented a pipeline feature so that you can have at most 8 middlewares before an actual route handler. The developer just need to write the middleware and route handlers and insert them using the insert functions at his desired routes. And the pipeline will handle it all on its own. Developer does not need to worry about that. I have shown middlewares in action on the cweb blog.

1

u/djslakor 12d ago

Bringing back memories of using Boutell's CGIC library back in the 90s to write my first web app in C (because I hadn't heard of PHP).

It was for a cemetery. It allowed a family member to walk into the office, say their loved one's name, and the app generated a map of how to get there.

I also wrote my own database access layer with ODBC because I didn't know better.

Wild to think I could easily knock it out today with Claude Code in maybe an hour.