
11 tracks. 479+ hands-on tasks. Write a tokenizer, parser, allocator, scheduler, and syscall handler yourself. Read free, pay only to run code. Launch pricing ends 31 Oct: $3/mo or $149 lifetime (normally $299).


Author of bit.ly/4qAksry (Order) builddistributedsystem.com (5.5k) lowlevelcraft.com (1.8k) youtube.com/@kernelkafe Support: buymeacoffee.com/mohitmishra…

11 tracks. 479+ hands-on tasks. Write a tokenizer, parser, allocator, scheduler, and syscall handler yourself. Read free, pay only to run code. Launch pricing ends 31 Oct: $3/mo or $149 lifetime (normally $299).



three servers need ids that never clash, and they can't ask each other first. a plain timestamp breaks fast. two nodes pick the same millisecond and you get the same id. snowflake packs three things into one 64 bit number: 41 bits of time in ms 10 bits of machine id 12 bits of sequence same ms on the same machine? bump the sequence. that's 4096 ids per ms per machine. other machines can't collide because their machine id is different. and since time sits in the high bits, the ids sort by when they were made. the hard part is a clock that jumps back after an ntp sync. you can build and break all of this in the identifier track on build distributed systems.


before postgres 18, reading a table looked like this: ask for one 8 KB block, wait for it, then ask for the next one. postgres 18 can put many block reads in flight at once and start working on the first ones while the rest are still coming. you choose how with io_method: - sync: the old way - worker: background processes do the reads - io_uring: linux's async io interface seq scans, bitmap heap scans and vacuum gain the most.


qsort doesn't know what it's sorting. it only gets a base pointer, a count, the size of one element, and your compare function. so your compare function never gets the elements. it gets pointers to them. sort an array of strings and each element is already a char *. so a and b are really char **. that's why you write strcmp(*(const char **)a, *(const char **)b) and not strcmp(a, b).


why does *NULL crash instead of just reading whatever is at address 0? because nothing is there, on purpose. the kernel leaves the lowest addresses of your process unmapped. touch them and the mmu finds no mapping, traps, and you get SIGSEGV. you can't easily map it yourself either. ask mmap for a page at 0x1000 and it says "Operation not permitted". your code usually sits up near 0x400000. the empty space below it is a guard zone.


you send 20 bytes of json to another service. that's not what goes on the wire. http puts its own lines on top: POST, Host, Content-Type, Content-Length. that alone is already bigger than your json. tcp adds at least 20 bytes: ports, sequence number, ack number, window. ip adds 20 more: source ip, destination ip, ttl. ethernet wraps all of it with 14 bytes (two mac addresses and a type) and a 4 byte crc at the end. the other side peels it off in reverse, one layer at a time.

Article: mohitmishra786.github.io/The…

free memory can still be useless. say three 32 byte blocks sit side by side on the heap and you free all of them. if the allocator only marks them free, a malloc(64) fits none of them. so it grows the heap with sbrk anyway. the fix is coalescing. on free, check the neighbors. if the next or previous block is free, add the sizes and make it one block. malloc does the reverse: take a big free block, split off what you need, keep the rest free.

Article Link: mohitmishra786.github.io/The…

in C, "2573" is just 4 bytes. how does it become the number 2573? '0' is 48, '1' is 49, and so on in order. so c - '0' gives you the digit. then go left to right: result = result * 10 + digit. 0 -> 2 -> 25 -> 257 -> 2573. that one loop is the heart of atoi. the real work is the edges: a minus sign, junk like "12ab", and numbers too big for an int. if you wrote your own, how would you catch overflow before it happens?

Article Link: mohitmishra786.github.io/The…