Skip to content

Instantly share code, notes, and snippets.

View CAFxX's full-sized avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
@CAFxX
CAFxX / The Case for Automated Granular Data Placement in Distributed Databases.md
Last active February 15, 2026 22:51
The Case for Automated Granular Data Placement in Distributed Databases

The Case for Automated Granular Data Placement in Distributed Databases

Two Roles, One Key

In every horizontally scalable database—Spanner, CockroachDB, YugabyteDB, TiDB, and their descendants—a primary key quietly serves two masters. It is a logical identifier, the application's stable handle for a specific entity. And it is a physical address, the value that determines which node in the cluster stores the row. These two roles are in fundamental tension.

The tension is visible within a single table. A Documents table keyed by DocumentId—a UUID chosen for global uniqueness—scatters documents uniformly across ranges, because range-partitioned databases assign rows to nodes based on key order. But if most transactions access documents belonging to the same tenant, the physical layout is exactly wrong: rows that are always read together are distributed as far apart as the key space allows. The logical choice (UUID for uniqueness) directly conflicts with the physical need (shared prefix for locali

@CAFxX
CAFxX / golang_minimize_allocations.md
Last active January 19, 2026 13:20
Minimize allocations in Go

📂 Minimize allocations in Go

A collection of tips for when you need to minimize the number of allocations in your Go programs.

Use the go profiler to identify which parts of your program are responsible for most allocations.

Caution

Never apply these tricks blindly (i.e. without measuring the actual performance benefit/impact).

[!NOTE]

@CAFxX
CAFxX / post.md
Last active January 12, 2026 02:45

The distance between deciding and doing is the single most reliable predictor of whether your life will be extraordinary or ordinary. Not talent, not circumstances, not even the quality of your decisions-but how quickly you collapse the space between intention and reality. Think of this gap as a kind of friction coefficient on your existence: the smaller it is, the more of your internal force actually translates into external motion. When you can move from "I should do this" to physically doing it within hours instead of weeks, you're not just accomplishing more-you're operating in a fundamentally different mode of being where your thoughts have immediate consequences in the world, where your inner life and outer life are in constant, tight conversation.

This matters profoundly because success isn't really about outcomes-it's about iteration speed. The person who can decide and act in the same breath gets ten attempts at something while someone with a week-long gap between decision and execution gets one. Th

@CAFxX
CAFxX / most_frequent_http_headers_keys.csv
Last active December 10, 2025 06:19
Most frequent 10000 HTTP headers keys/values
item frequency
user-agent 739871221
accept-encoding 733869339
accept-language 733614410
accept 729745441
date 724032586
sec-fetch-mode 723555429
sec-fetch-site 723539507
sec-fetch-dest 723538347
content-type 718705785
@CAFxX
CAFxX / golang_bulk_alloc.md
Last active December 5, 2025 05:57
Golang bulk allocations

Bulk memory allocations for Go

Consider the following code:

s := make([]*Foo, N)
for i := range s {
  s[i] = new(Foo)
  // ...
}
@CAFxX
CAFxX / interncache.go
Created December 3, 2025 03:20
interncache
package interncache
import (
"encoding/binary"
"iter"
"maps"
"math"
"math/bits"
"math/rand/v2"
"sync/atomic"
@CAFxX
CAFxX / go_wishlist.md
Last active November 6, 2025 02:15
Go wishlist

Language/syntax

Shorthand error definition

Instead of things like var ErrFoo = errors.New("foo") or return fmt.Errorf("foo: %d", n) I would like a shorthand syntax that allows to define a new error type.

Simple error

@CAFxX
CAFxX / 00_cpu_wishlist.md
Last active October 21, 2025 08:18
CPU ISA and implementation wishlists
@CAFxX
CAFxX / persistent_pipes_linux.md
Last active October 20, 2025 04:17
Persistent pipes/circular buffers for Linux

📂 Persistent "pipes" in Linux

In a project I'm working on I ran into the requirement of having some sort of persistent FIFO buffer or pipe in Linux, i.e. something file-like that could accept writes from a process and persist it to disk until a second process reads (and acknowledges) it. The persistence should be both across process restarts as well as OS restarts.

AFAICT unfortunately in the Linux world such a primitive does not exist (named pipes/FIFOs do not persist

@CAFxX
CAFxX / genRangeTableCode.go
Last active October 13, 2025 08:25
unicode.RangeTable code generator
package main
import (
"fmt"
"math/bits"
"slices"
"sort"
"strings"
"unicode"
)