DEV Community

Cover image for Is Creating Custom WebServer Hard?
Tom J.
Tom J.

Posted on Originally published at tomj.pro

Is Creating Custom WebServer Hard?

Yes and no. The basic functionality is very, veeery easy. But once you start dealing with the reality of the Internet and uptime, you very likely have a project for at least 6 months.

The Basics Of a WebServer Are Dead Simple

First, you connect to TCP, which is handled by your favorite OS.

Then you make some kind of routing by domain (and maybe port if you are being fancy) to that application - a binary, direct HTML files, anything you want it to be.

Simple JSON probably suffice here.

Lastly, you implement or use libraries for HTTP/1 and HTTP/2 (and subversions) protocol. Just text protocols, not difficult.

Oh, and SSL. But no worries, OpenSSL got you covered with it's full TLS implementation.

That's it. This is literally a webserver. Go ahead, deploy it, try it. It's fine,

I can wait before I continue... It won't take the internet long before it breaks your first webserver.

What Happens? Why Would It Break?

Well, this set up is too simple. These days, HTTP comes at you with a tone of different headers.

Not just that, Online traffic doesn't play nicely. It literally tries to break your webserver. In the basic setup, you don't care about resources or abusive traffic. You don't expect it, really.

HTTP itself doesn't even have any anti-abuse gates. It has some mechanisms for users and browser protection, but not server's.

So the most basic problem on small VPS at least? Bots and probes can start hitting you so hard that it can look like DDoS attack - it's not, it's a normal online world. But you probably exhaust all your memory and CPU cores very quickly.

How About Security Of This Basic WebServer?

That's actually interesting. In such a basic setup, there is nothing really insecure. If you did a proper validation and you need to just serve html and static resources, you can actually be golden!

But that is not the case probably. Is it? You don't go all this way just for static webpages. Unless you are doing it to learn networking... You are? That's awesome! Great job!

Natural Expansion Of Your WebServer

Gzip compression comes to mind as first next step. It's kind of standard these days for fast network transport.

You may want a Cache in the server. Maybe just HTTP headers, but maybe to list and keep frequent requests in memory. And that alone is worth of a nice Sunday migrane.

The websites are not just static html, not usually. Therefore there must be a process that the webserver will run. Which introduces you to a process management. But hey, now you can run an actual application.

Access logging is a cool feature. Don't let it grow indefinetelly though - delete old or compress it.

Let me tell you what I decided for our WebServer

We created an ABI between server and apps. The webserver itself is more simplistic. And the app has most of the functionality. Caching, gzipping. The server offers typical web options, but let's the websites apply them.

My reasoning is that these days there are 3 layers trying to do one thing - the website, the webserver and OS or often some proxy layer.

I swear, it's like every single piece is trying to cache my CSS file and as soon as a client tells me "but I am not seeing it", I get furious at that unidentified piece that is keeping it out of sync!

So, we just let each part to do its own job.

Keeping WebServer's 100% Availability

This was a big one for us. One of the main reasons to create Grace WebServer was to control availability.

Which means that no change must require restart of the server nor a single website. And we are achieving it slowly.

For example, changing domains of a website or its ports (yes, we put ports to each website's settings) must never put the website out, not even a microsecond.

So, when a the domain changes, for illutrative purposes let's say one website has one domain and we change it for a different one, there's this process:

  1. the webserver activates the new domain, checks availability
  2. it starts receiving traffic here and cuts off the old one
  3. only after the old one gets emptied, all connections are closed, no more traffic exists there, it gets removed.

Can you imagine doing this for each and every single setting? Granted, not all need to be this elaborate, but still, each setting now needs more than a single path - it needs start, stop AND "whatever changed".

And when you are finished, you end up with a very big webserver coding project that left the first basic set up in middle ages.

What About Grace WebServer And Its Current State?

It is being tested. We have nicely implemented even HTTP/3 with QUIC, absolutely clear boundaries between the server and apps, basic request filtering, on-the-fly changes with 0 downtime for them...

And full UI. Yes, we have CLI if you really want it. MCP even. But for me, having UI is priority. Native UI, not a web one. I guess I just love the name Vulkan. Oh, and it's remote. I am not bothering runtime VPS with running UI. Not that crazy, man, not that much.

It is not production ready yet, but it's online, we're seeing what it does and my guess is that Q2 - Q3 2027, it'll see first actual client apps. And I can't wait, because they'll be running in literal CPU speed!

Top comments (0)