dwyl / dwyl/learn-zig

Deploy my beast on Hetzner

Open
#29 22 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
4
Forks
1
PR merge metrics
No merged PRs in 30d

Description

I want to deploy my SSR `Zig` shopping cart on a VPS to see it working in "production" and how it handles load.

Target: 4€/month.

Why VPS? Because it is just an executable, that can be compiled to whatever target. No Docker overhead needed. No reverse-proxy neither needed.

[Image](https://www.hetzner.com/cloud)

➡️ I opted for the `CX22`, 2VCPU, 4GB RAM with an IPV4 (IPV6 is more difficult to interact with, does not accept `scp -6`).

The app is a `Zig` SSR webapp. It runs a WebSocket per connection, just like `Presence` to monitor and display the number of connected users, but more importantly to dump the shopping cart (in memory) when the user disconnects.
This mimics `LiveView` which keeps everything in its socket, thus memory consumption grows linearly with the number of connected users.
I use SQLite for my grocery list, and retrieve the price from it on every item mouvement. SQLite sustains this high _read_ rate without complaining!

`Zig` makes _VERY_ performant apps! To give an idea, I can sustain locally 50 kreq/s (180M req/h), meaning > 10.000 users online interacting every 100ms with response time < 50ms. Memory usage is very low (< 100Mb). Another world.

It is a bit more complicated to code than `Phoenix/Liveview`, especially when getting _segfault_, meaning race conditions or invalid pointers.
I also had to fight with `HTMX` but it turns to be manageable. Every action makes a round trip to the server, hitting an endpoint. It is clearly the opposite of "optimistic rendering", when the client action is supposed to succeed, and the server can afterwards invalidate it. With `HTMX`, it is server first.
The client code is very small: just _20kB_, no JS bloat at all.


Image
Image

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.