---
title: "Discussion on \"7 Lessons I Learned Building Production APIs in Go\" | Hashnode"
description: "Discussion on \"7 Lessons I Learned Building Production APIs in Go\". TL;DR: After shipping several production systems in Go — coming from PHP/Laravel — these are the eight lessons that actually mattered: boring project structure, context.Context everywhere, fixing the"
url: "https://hashnode.com/posts/7-lessons-i-learned-building-production-apis-in-go/6ac96753d8fd56894cb40ba6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [7 Lessons I Learned Building Production APIs in Go](https://parsaaftabi.hashnode.dev/7-lessons-i-learned-building-production-apis-in-go?utm_source=hashnode&utm_medium=feed)

TL;DR: After shipping several production systems in Go — coming from PHP/Laravel — these are the eight lessons that actually mattered: boring project structure, context.Context everywhere, fixing the

Oct 9 · 6 min read · parsaaftabi.hashnode.dev  
Updated Nov 16  
Read the article

-   [#go](https://hashnode.com/tag/go)
-   [#backend](https://hashnode.com/tag/backend)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#programming-languages](https://hashnode.com/tag/programming-languages)

## Written by

[Parsa Aftabi](https://hashnode.com/@parsaaftabi)

@parsaaftabi

  
[View profile](https://hashnode.com/@parsaaftabi)

I do computers, all the way down. Go and C++. I build small tools and write about how systems fail.

I do computers, all the way down. Backend and systems work in Go and C++, small open-source tools, and a low-level series on crash logs, page tables and kernel internals.

## Responses 2

Markdown supported · ⌘↵ to post

[Hamed Yousefi](https://hashnode.com/@hmdsefi)

[Oct 10](https://hashnode.com/posts/7-lessons-i-learned-building-production-apis-in-go/6ac96753d8fd56894cb40ba6/comment/6aca137163ebfab1e9507885)

Really useful post, thanks. Lesson 3 hit home for me: the slow endpoint is usually a missing index, and adding the index is cheaper than adding a cache.

A small tip for lesson 5: staticcheck warns about a plain string as a context key, because another package can use the same string. An unexported key type avoids that:

type requestIDKey struct{}

ctx := context.WithValue(r.Context(), requestIDKey{}, id)

And one I'd add to the list: set timeouts on http.Server itself, at least ReadHeaderTimeout. A slow client can hold a connection open while it sends headers, and that happens before the handler runs, so the context timeout from lesson 2 never starts.

[Parsa Aftabi](https://hashnode.com/@parsaaftabi)

[Oct 10](https://hashnode.com/posts/7-lessons-i-learned-building-production-apis-in-go/6ac96753d8fd56894cb40ba6/comment/6aca137163ebfab1e9507885#reply-6aca298119d143c3fef8e715)

Appreciate the careful read, Hamed. You're right on lesson 5. An unexported struct type as the context key is the right call over a plain string, and the staticcheck warning is a good reminder. I'll tighten that section. And the ReadHeaderTimeout suggestion is a genuinely good addition. Most handlers think about request timeouts but forget slowloris-style clients can tie up the listener before a request ever forms. I'll add a lesson on server timeouts.
