This book is designed as a series of projects that introduce the fundamental and powerful techniques of systems programming, one by one. Each chapter discusses an important topic in systems programming, and in the spirit of adventure, we may not always take the most direct route to our destination. Sometimes it’s best to make a few mistakes, or do things by hand a few times before we skip ahead to the “right answer.”
The work will all pay off, though. As you progress and master more and more techniques, you will gradually put the pieces together into something greater than the sum of its parts. And by the end, not only will you have the code for a lightweight, asynchronous microservice framework, you’ll also be able to write one yourself if you don’t like the way I did it.
The book is divided into two parts:
Part I dives into the fundamental techniques of systems programming using the basic facilities that UNIX-based operating systems have had since the 1980s. Unlike traditional systems programming books, however, networking is introduced early. For a modern programmer, working with remote services over HTTP is more relevant and practical than local file I/O. I then introduce process-based concurrency and parallelism. Although most Scala programmers will be more familiar with threads, processes are a powerful technique that distinguishes Scala Native from most other programming languages, and they’re a great, safe introduction to asynchronous programming. We then look at combining these techniques to build a minimalist HTTP server and measure its performance with a simple stress test. However, we also look at the limits of these traditional techniques.
In Part II, we’ll put the “modern” in “modern systems programming.” From this point on, all of our code will be fully asynchronous, building upon the capabilities of the event loop library, libuv. Working with an industrial-strength C library like this, we’ll introduce new complexities to our code, but it also gives Scala Native a chance to truly shine. With libuv, we’ll revisit our HTTP server, introduce idiomatic Scala concurrency techniques, and learn how to work with durable data stores. Then, when we put those components together, we’ll have built a framework for solving real-world problems. I’m skeptical of buzzwords, but the low overhead and light footprint of Scala Native code really does put JVM-based “microservices” to shame.