Why I Reach for Go When Building Web3 Backends

I have been writing Go professionally for over a year now, mainly for the backend of Web3 products. Before that I was mostly JavaScript and Python. I want to write down why Go has become my default choice for anything backend in the Web3 space, because I wish someone had told me this earlier.

The Concurrency Thing is Real

When you’re building something that listens to blockchain events — indexing transactions, watching contract events, syncing state — you need concurrency that doesn’t make you want to cry. Go’s goroutines are genuinely easy to use compared to JavaScript’s async/await chains or Python’s asyncio.

A simple example: listening to multiple smart contract events simultaneously and writing them to a database. In Go this is a handful of goroutines and a few channels. Clean and readable.

go-ethereum is Excellent

The go-ethereum library (geth) is the reference Ethereum client and it’s written in Go. Using it from Go feels native in a way that doesn’t quite translate to other languages. You can subscribe to events, call contract functions, sign and send transactions — all with proper types, none of the any and casting chaos I used to deal with in TypeScript.

client, err := ethclient.Dial("wss://mainnet.infura.io/ws/v3/YOUR_KEY")
if err != nil {
    log.Fatal(err)
}

query := ethereum.FilterQuery{
    Addresses: []common.Address{contractAddress},
}

logs := make(chan types.Log)
sub, err := client.SubscribeFilterLogs(context.Background(), query, logs)

That’s it. No callback hell. Errors are explicit. I know exactly what’s happening.

Performance Matters at Scale

On a busy chain like Polygon or during a token launch, your backend might be processing hundreds of events per second. Go’s performance here is just in a different league from Python. I noticed this the first time we had a high-traffic period at work — the Go service barely moved on CPU, while the old Python service we had experimented with earlier would have been struggling.

The Learning Curve is Honest

Go is opinionated and the error handling is verbose. Writing if err != nil fifty times per file feels tedious at first. But this explicitness saved me multiple times when I was new to the codebase — every failure path is explicit, not hidden behind an exception that might bubble up in a weird way.

If you are coming from JavaScript, the static typing will also feel restrictive initially. Give it two weeks. You’ll miss it in every other language after that.

What I’m Building With It Now

Currently using Go to build a token-gating API — it checks NFT ownership and issues signed session tokens for gated content access. Go’s standard library handles the crypto primitives really well, and the binary compiles to a single self-contained executable which makes deployment painless.

If you are building anything in the Web3 backend space and haven’t tried Go, I’d really recommend it. The ecosystem is mature and the language is genuinely a pleasure once it clicks.

為什麼我做 Web3 後端都選 Go?

我現在用 Go 寫後端已經超過一年了,主要是為 Web3 產品開發後端服務。在這之前,我大部分時候都在用 JavaScript 和 Python。想把這些心得寫下來,說說 Go 是怎麼成為我 Web3 後端開發的預設選擇——因為我希望有人早點跟我說這件事。

並發(Concurrency)真的很重要

當你在做監聽區塊鏈事件的東西——索引交易、監聽合約事件、同步狀態——你需要一種不會讓你抓狂的並發機制。Go 的 goroutine 跟 JavaScript 的 async/await 巢狀結構,或 Python 的 asyncio 相比,真的容易用多了。

一個簡單的例子:同時監聽多個智能合約事件並寫入資料庫。在 Go 裡,幾個 goroutine 加上幾個 channel 就搞定了,程式碼乾淨又好讀。

go-ethereum 非常好用

go-ethereum 函式庫(也就是 geth)是以太坊的參考用戶端,用 Go 撰寫。從 Go 直接呼叫它,有一種原生的感覺,是其他語言比不上的。你可以訂閱事件、呼叫合約函式、簽名並發送交易——全部都有完整的型別,不像 TypeScript 那樣到處是 any 和型別轉換的混亂。

client, err := ethclient.Dial("wss://mainnet.infura.io/ws/v3/YOUR_KEY")
if err != nil {
    log.Fatal(err)
}

query := ethereum.FilterQuery{
    Addresses: []common.Address{contractAddress},
}

logs := make(chan types.Log)
sub, err := client.SubscribeFilterLogs(context.Background(), query, logs)

就這樣。沒有回呼地獄,錯誤處理一目了然,我知道每一步都在幹嘛。

效能在大規模時很關鍵

在 Polygon 這種繁忙的鏈上,或是代幣發行期間,後端每秒可能要處理幾百個事件。Go 在這方面的效能跟 Python 根本不是同個量級。我在工作中第一次遇到流量高峰的時候就感受到了——Go 服務的 CPU 幾乎沒有波動,而我們之前實驗性用的 Python 服務在那種情況下早就掙扎了。

學習曲線是誠實的

Go 有自己的風格,錯誤處理很囉嗦。每個函式都要寫一遍 if err != nil 一開始感覺很煩。但這種明確性讓我好幾次在讀別人的程式碼時救了我——每個失敗路徑都清清楚楚,不會有異常突然從奇怪的地方冒出來。

如果你是從 JavaScript 轉過來,靜態型別一開始也會讓你覺得很受限。撐過兩個禮拜。之後你在用其他語言的時候反而會想念它。

現在在用它做什麼

目前用 Go 在開發一個代幣閘道(token-gating)API——它會檢查 NFT 持有情況,並為受保護的內容發放已簽名的 session token。Go 的標準函式庫對加密相關操作的支援很好,而且編譯出來的是單一的獨立執行檔,部署超方便。

如果你在做 Web3 後端的東西,還沒試過 Go,真的值得試試看。生態系成熟,語言本身在熟悉之後也真的很好用。