GC shape stenciling in Go generics

How Go's compiler shares generic function bodies by GC shape and uses dictionaries for the concrete types. | Continue reading


@rednafi.com | 11 days ago

Modernizers & go fix

Go 1.26 rebuilt go fix on the analysis framework. It modernizes your code and respects the Go version your module declares. The post covers the modernizers, the bigger x/tools suite, and what //go:fix inline can and can't migrate. | Continue reading


@rednafi.com | 18 days ago

Request coalescing with Go singleflight

A hot cache key expires and a hundred requests issue the same query at once, saturating the database. Go's singleflight package coalesces those duplicate calls into one. How to wire it up, how to measure whether it's firing, and why per-pod coalescing is usually enough. | Continue reading


@rednafi.com | 25 days ago

Channel iteration and goroutine leak

A for-range over an unclosed channel leaks the receiver. Why three explicit receives are safe, why a range isn't, and catching it with Go 1.27's leak profile. | Continue reading


@rednafi.com | 1 month ago

Accepted proposal: a goroutine leak profile in the Go standard library

Notes on Go's accepted goroutine leak profile and how it reuses the GC to find them. | Continue reading


@rednafi.com | 1 month ago

Reading your own writes with WAIT FOR LSN in Postgres 19

PostgreSQL 19's new WAIT FOR LSN command lets a replica block until it has replayed your write. The read-after-write problem it solves, the workarounds it replaces, and what the timeout, status, and mode options are actually for. | Continue reading


@rednafi.com | 1 month ago

Migrating from GNU stow to chezmoi

Why I swapped GNU stow's symlink farm for chezmoi: one command to bootstrap a Mac with Homebrew packages and macOS settings, a small daily sync loop, and agent skills shared between Claude Code and Codex. | Continue reading


@rednafi.com | 1 month ago

Putting this blog on ATProto with standard.site

Mirroring a static Hugo blog onto ATProto with standard.site and Sequoia, plus the GitHub Actions wiring that republishes the records on every push without any manual steps. | Continue reading


@rednafi.com | 1 month ago

If you won't carry the pager, maybe don't push to mainline

Drive-by AI changes break the shared model a team builds around its code, and the ICs end up cleaning up the mess. Why pushing to mainline should come with the pager. | Continue reading


@rednafi.com | 1 month ago

Testing Go CLIs with testscript

How cmd/go's script tests led me to testscript, and how to use it for CLI tests that exercise argv, stdout, stderr, exit codes, and scratch files. | Continue reading


@rednafi.com | 2 months ago

A tour of txtar

txtar is a tiny plain-text archive format Russ Cox introduced in 2018 for multi-file test fixtures. The Go Playground, cmd/go's script tests, gopls's marker tests, and rsc.io/rf all reach for it. | Continue reading


@rednafi.com | 2 months ago

Type-safe slogging

The default slog API is loose enough that a careless line ships broken JSON to production. Pin it down with Attr constructors, LogAttrs, a context-borne logger, and sloglint. | Continue reading


@rednafi.com | 2 months ago

Hoisting wire plumbing out of your Go handlers

Four of the five steps in every unary RPC handler are wire plumbing. Pin the service function signature and they fit in one generic adapter per transport. | Continue reading


@rednafi.com | 2 months ago

Go quirks: function closures capturing mutable references

A Go closure holds a live reference to whatever it captures, not a snapshot. Real examples of where this trips people up, and how to keep it boring. | Continue reading


@rednafi.com | 2 months ago

Accepted proposal: UUID in the Go standard library

Notes on Go's newly accepted uuid proposal and the tradeoffs behind the API. | Continue reading


@rednafi.com | 3 months ago

Peeking into Go struct tags

A quick tour of Go struct tags: how different libraries use them, how you read them at runtime with reflection, and how other tools read them at build time instead. | Continue reading


@rednafi.com | 3 months ago

Fun with Go struct tags

A quick tour of Go struct tags: how different libraries use them, how you read them at runtime with reflection, and how other tools read them at build time instead. | Continue reading


@rednafi.com | 3 months ago

UUIDs are coming to the Go stdlib

Go's proposal review group accepted a new uuid package with v4 and v7 generators. Here are the decisions that shaped the final API. | Continue reading


@rednafi.com | 3 months ago

Error translation in Go services

Translating errors at layer boundaries so storage details don't leak into the handler or, worse, into client responses. | Continue reading


@rednafi.com | 3 months ago

Dynamo: Amazon's highly available key-value store

Key takeaways from Amazon's 2007 Dynamo paper. | Continue reading


@rednafi.com | 3 months ago

Stacked log lines considered harmful

Why logging at every layer of a service produces noise, and how to log only at the handler level while propagating context from below. | Continue reading


@rednafi.com | 3 months ago

What's the ideal dispatch mechanism?

Switch, map of functions, and interface registry for dispatching in Go. | Continue reading


@rednafi.com | 3 months ago

Background jobs and inherited file descriptors

Why & backgrounds execution but doesn't stop output from flooding your terminal. | Continue reading


@rednafi.com | 3 months ago

Testing unary gRPC services in Go

How to test unary gRPC services in Go - handler logic, interceptors, deadlines, metadata propagation, and rich error details - all in-memory with bufconn. | Continue reading


@rednafi.com | 4 months ago

Repositories, transactions, and unit of work in Go

Decoupling business logic from storage in Go, adding transaction support without leaking SQL details, and coordinating atomic writes across multiple repositories using a unit of work. | Continue reading


@rednafi.com | 4 months ago

How do you handle transactions with the repository pattern?

Adding transaction support to a repository interface without leaking storage details. | Continue reading


@rednafi.com | 4 months ago

Is passing user ID through context an antipattern?

Why the middleware-to-handler boundary is a special case for context values. | Continue reading


@rednafi.com | 4 months ago

What belongs in Go's context values

A simple litmus test for when to use context values in Go. | Continue reading


@rednafi.com | 4 months ago

Do you need a repository layer on top of sqlc?

Decoupling business logic from storage with a small interface in Go. | Continue reading


@rednafi.com | 4 months ago

Wrapping a gRPC client in Go

How to wrap a generated gRPC client behind a clean Go API so users never have to touch protobuf types or connection management directly. | Continue reading


@rednafi.com | 4 months ago

In praise of the etcd codebase

Why the etcd codebase is my go-to reference for building gRPC services in Go. | Continue reading


@rednafi.com | 4 months ago

Go errors: to wrap or not to wrap

Exploring the tradeoffs between wrapping errors at every return site versus wrapping only at boundaries, with no definitive answer - just honest tradeoffs for the kind of software I write. | Continue reading


@rednafi.com | 4 months ago

Safe mutation with mutex closures

Why your mutex wrapper should accept a closure for mutation instead of a plain value, with examples from the standard library and Tailscale. | Continue reading


@rednafi.com | 4 months ago

Debugging context cancellation in Go

How Go 1.20's WithCancelCause and Go 1.21's WithTimeoutCause let you attach a reason to context cancellation, plus a gotcha with manual cancel and the stdlib pattern that covers every path. | Continue reading


@rednafi.com | 4 months ago

Structured concurrency & Go

How Python and Kotlin provide structured concurrency out of the box while Go achieves the same patterns explicitly using errgroup, WaitGroup, and context. | Continue reading


@rednafi.com | 5 months ago

Your Go tests probably don't need a mocking library

Practical patterns for mocking in Go without external libraries. Learn to mock functions, methods, interfaces, HTTP calls, and time using only the standard library | Continue reading


@rednafi.com | 6 months ago

Mocking Go code without a library

Practical patterns for mocking in Go without external libraries. Learn to mock functions, methods, interfaces, HTTP calls, and time using only the standard library | Continue reading


@rednafi.com | 6 months ago

Tap compare testing for service migration

Throughout the years, I’ve been part of a few medium- to large-scale system migrations. As in, rewriting old logic in a new language or stack to gain better scalability, resilience, and maintainability, or to respond more easily to changing business requirements. Whether rewritin … | Continue reading


@rednafi.com | 7 months ago

Splintered failure modes in Go

A man with a watch knows what time it is. A man with two watches is never sure. — Segal’s law Take this example: func validate(input string) (bool, error) { if input == "" { return false, nil } if isCorrupted(input) { return false, fmt.Errorf("corrupt … | Continue reading


@rednafi.com | 7 months ago

Re-exec testing Go subprocesses

When testing Go code that spawns subprocesses, you usually have three options. Run the real command. It invokes the actual binary that creates the subprocess and asserts against the output. However, that makes tests slow and tied to the environment. You have to make sure the same … | Continue reading


@rednafi.com | 8 months ago

Revisiting interface segregation in Go

Object-oriented (OO) patterns get a lot of flak in the Go community, and often for good reason. Still, I’ve found that principles like SOLID, despite their OO origin, can be useful guides when thinking about design in Go. Recently, while chatting with a few colleagues new to Go, … | Continue reading


@rednafi.com | 8 months ago

Avoiding collisions in Go context keys

Along with propagating deadlines and cancellation signals, Go’s context package can also carry request-scoped values across API boundaries and processes. There’s only two public API constructs associated with context values: func WithValue(parent Context, key, val any) Context fu … | Continue reading


@rednafi.com | 9 months ago

Organizing Go tests

When it comes to test organization, Go’s standard testing library only gives you a few options. I think that’s a great thing because there are fewer details to remember and fewer things to onboard people to. However, during code reviews, I often see people contravene a few common … | Continue reading


@rednafi.com | 9 months ago

Organizing Go tests

When it comes to test organization, Go’s standard testing library only gives you a few options. I think that’s a great thing because there are fewer details to remember and fewer things to onboard people to. However, during code reviews, I often see people contravene a few common … | Continue reading


@rednafi.com | 9 months ago

Subtest grouping in Go

Go has support for subtests starting from version 1.7. With t.Run, you can nest tests, assign names to cases, and let the runner execute work in parallel by calling t.Parallel from subtests if needed. For small suites, a flat set of t.Run calls is usually enough. That’s where I t … | Continue reading


@rednafi.com | 9 months ago

Subtest grouping in Go

Go has support for subtests starting from version 1.7. With t.Run, you can nest tests, assign names to cases, and let the runner execute work in parallel by calling t.Parallel from subtests if needed. For small suites, a flat set of t.Run calls is usually enough. That’s where I t … | Continue reading


@rednafi.com | 9 months ago

Let the domain guide your application structure

I like to make the distinction between application structure and architecture. Structure is how you organize the directories and packages in your app while architecture is how different components talk to each other. The way your app talks to other services in a fleet can also be … | Continue reading


@rednafi.com | 10 months ago

Let the domain guide your application structure

I like to make the distinction between application structure and architecture. Structure is how you organize the directories and packages in your app while architecture is how different components talk to each other. The way your app talks to other services in a fleet can also be … | Continue reading


@rednafi.com | 10 months ago