
The Backend Engineering Show with Hussein Nasser
Welcome to the Backend Engineering Show podcast with your host Hussein Nasser. If you like software engineering you’ve come to the right place. I discuss all sorts of software engineering technologies and news with specific focus on the backend. All opinions are my own.
Most of my content in the podcast is an audio version of videos I post on my youtube channel here http://www.youtube.com/c/HusseinNasser-software-engineering
Buy me a coffee
https://www.buymeacoffee.com/hnasr
🧑🏫 Courses I Teach
https://husseinnasser.com/courses
Latest episodes

Sep 20, 2024 • 21min
How many kernel calls in NodeJS vs Bun vs Python vs native C
Fundamentals of Operating Systems Course
https://oscourse.win
In this video I use strace a performance tool that measures how many system calls does a process makes. We compare a simple task of reading from a file, and we run the program in different runtimes, namely nodejs, buns , python and native C.
We discuss the cost of kernel mode switches, system calls and pe
0:00 Intro
5:00 Code Explanation
6:30 Python
9:30 NodeJS
12:30 BunJS
13:12 C
16:00 Summary

Sep 13, 2024 • 31min
When do you use threads?
Fundamentals of Operating Systems Course
https://os.husseinnasser.com
When do you use threads?
I would say in scenarios where the task is either
1) IO blocking task
2) CPU heavy
3) Large volume of small tasks
In any of the cases above, it is favorable to offload the task to a thread.
1) IO blocking task
When you read from or write to disk, depending on how you do it and the kernel interface you used, the write might be blocking. This means the process that executes the IO will not be allowed to execute any more code until the write/read completes.
That is why you see most logging operations are done on a secondary thread (like libuv that Node uses) this way the thread is blocked but the main process/thread can resume its work.
If you can do file reads/writes asynchronously with say io_uring then you technically don't need threading.
Now notice how I said file IO because it is different than socket IO which is always done asynchronously with epoll/select etc.
2) CPU heavy
The second use case is when the task requires lots of CPU time, which then starves/blocks the rest of the process from doing its normal job. So offloading that task to a thread so that it runs on a different core can allow the main process to continue running on its the original core.
3) Large volume of small tasks
The third use case is when you have large amount of small tasks and single process can't deliver as much throughput. An example would be accepting connections, a single process can only accept connections so fast, to increase the throughput in case where you have massive amount of clients connecting, you would spin multiple threads to accept those connections and of course read and process requests. Perhaps you would also enable port reuse so that you avoid accept mutex locking.
Keep in mind threads come with challenges and problems so when it is not required.
0:00 Intro
1:40 What are threads?
7:10 IO blocking Tasks
17:30 CPU Intensive Tasks
22:00 Large volume of small tasks

4 snips
Sep 7, 2024 • 25min
Frontend and Backends Timeouts
Dive into the intriguing world of timeouts in programming! Discover how they manage waiting periods, free up resources, and even fend off potential DOS attacks. Learn about different types of timeouts like connection and response, and their broader applications beyond just request processing. Engaging discussions highlight best practices for optimizing client-server interactions and ensuring efficient request handling. Prepare for unexpected insights that could change how you think about frontend and backend communications!

Sep 2, 2024 • 28min
Postgres is combining IO in version 17
Learn more about database and OS internals, check out my courses
Fundamentals of database engineering https://databases.win
Fundamentals of operating systems https://oscourse.win
This new PostgreSQL 17 feature is game changer.
You see, postgres like most databases work with fixed size pages. Pretty much everything is in this format, indexes, table data, etc. Those pages are 8K in size, each page will have the rows, or index tuples and a fixed header. The pages are just bytes in files and they are read and cached in the buffer pool.
To read page 0, for example, you would call read on offset 0 for 8192 bytes, To read page 1 that is another read system call from offset 8193 for 8192, page 7 is offset 57,345 for 8192 and so on.
If table is 100 pages stored a file, to do a full table scan, we would be making 100 system calls, each system call had an overhead (I talk about all of that in my OS course).
The enhancement in Postgres 17 is to combine I/Os you can specify how much IO to combine, so technically while possible you can scan that entire table in one system call doesn’t mean its always a good idea of course and Ill talk about that.
This also seems to included a vectorized I/O, with preadv system call which takes an array of offsets and lengths for random reads.
The challenge will become how to not read too much, say I’m doing a seq scan to find something, I read page 0 and found it and quit I don’t need to read any more pages. With this feature I might read 10 pages in one I/O and pull all its content, put in shared buffers only to find my result in the first page (essentially wasting disk bandwidth, memory etc)
It is going to be interesting to balance this out.

Aug 30, 2024 • 37min
Windows vs Linux Kernel
Fundamentals of Operating Systems Course
https://os.husseinnasser.com
Why Windows Kernel connects slower than Linux
I explore the behavior of TCP/IP stack in Windows kernel when it receives a RST from the backend server especially when the host is available but the port we are trying to connect to is not. This behavior is exacerbated by having both IPv6 and IPv4 and if the happy eye ball protocol is in place where IPv6 is favorable.
0:00 Intro
0:30 Fundamentals TCP/IP
3:00 Unreachable Port Behavior
6:00 Client Kernel Behavior (Linux vs Windows)
11:40 Slow TCP Connect on Windows
15:00 localhost, IPv6 and IPv4
20:00 Happy Eyeballs
28:00 Registry keys to change the behavior
31:00 Port Unreachable vs Host Unreachable
https://daniel.haxx.se/blog/2024/08/14/slow-tcp-connect-on-windows/

Aug 25, 2024 • 20min
Running out of TCP ephemeral source ports
In this episode of the backend engineering show I describe an interesting bug I ran into where the web server ran out of ephemeral ports causing the system to halt.
0:00 Intro
0:30 System architecture
2:20 The behavior of the bug
4:00 Backend Troubleshooting
7:00 The cause
15:30 Ephemeral ports on loopback

May 20, 2024 • 17min
io uring gets even faster
Linux I/O expert Jens Axboe discusses IO_uring updates for Linux 6.10, focusing on zerocopy. Topics include how normal copying works, zero copy benefits in data transfer, and challenges of SSL/TLS encryption. Explore advancements in kernel technology for efficient data handling.

May 7, 2024 • 29min
They made Python faster with this compiler option
Fundamentals of Operating Systems Course
https://oscourse.win
Looks like fedora is compiling cpython with the -o3 flag, which does aggressive function inlining among other optimizations.
This seems to improve python benchmarks performance by at most 1.16x at a cost of an extra 3MB in binary size (text segment). Although it does seem to slow down some benchmarks as well though not significantly.
O1 - local register allocation, subexpression elimination
O2 - Function inlining only small functions
O3 - Agressive inlining, SMID
0:00 Intro
1:00 Fedora Linux gets Fast Python
5:40 What is Compiling?
9:00 Compiling with No Optimization
12:10 Compiling with -O1
15:30 Compiling with -O2
20:00 Compiling with -O3
23:20 Showing Numbers
Backend Troubleshooting Course
https://performance.husseinnasser.com

Apr 29, 2024 • 34min
How Apache Kafka got faster by switching ext4 to XFS
Allegro improved Kafka latency by 80% switching from ext4 to XFS. They traced Kafka protocol and kernel system calls, optimized ext4 before switching. Show explores file system complexities, journaling impact, and challenges of workload increase.

Mar 5, 2024 • 14min
Google Patches Linux kernel with 40% TCP performance
Get my backend course https://backend.win
Google submitted a patch to Linux Kernel 6.8 to improve TCP performance by 40%, this is done via rearranging the tcp structures for better cpu cache lines, I explore this here.
0:00 Intro
0:30 Google improves Linux Kernel TCP by 40%
1:40 How CPU Cache Line Works
6:45 Reviewing the Google Patch
https://www.phoronix.com/news/Linux-6.8-Networking
https://lore.kernel.org/netdev/20231129072756.3684495-1-lixiaoyan@google.com/
Discovering Backend Bottlenecks: Unlocking Peak Performance
https://performance.husseinnasser.com