Duncan Leung

Backend

01

Module-Load Env Guards in Next.js: Structural Validation Beyond process.env Checks

nextjstypescriptbackendsecurity

Most env-var validation checks that values exist. That catches missing config but misses the worse case - a value that is present, valid in shape, and silently wrong. Here is the asymmetric pattern for separating loud failures from silent ones in a Next.js server.

02

Producer, Service, ProducerService: Interface Segregation for Shared Singletons in Go

backendgo

When one Go struct legitimately serves multiple consumer roles - producer, service, admin - declare three interfaces and let DI cache the singleton at the wide type while each consumer holds only the methods it can call. Same shape as io.ReadWriteCloser in the stdlib.

03

Idempotent SQS Workers with Postgres UPDATE: The WHERE-Status Pattern

backendgoawspostgres

Most SQS idempotency guides reach for Redis dedupe keys or dedupe tables. If your worker's job ends in a terminal state-machine transition, the row's own status column is already the lock - and one UPDATE statement is the entire safety story.

04

Go Idioms: Accept Interfaces, Return Types

backendgo

Understanding the Go idiom of accepting interfaces and returning concrete types to write flexible, reusable, and maintainable code.

05

Allocating Memory in Go

backendgo

Understanding memory allocation in Go, including stack vs heap allocation, escape analysis, and how Go handles pointer returns from functions.

06

Methods in Go

backendgo

Understanding Go methods, the difference between value and pointer receivers, embedding for composition, and how interfaces work with methods.

07

Slices in Go

backendgo

Understanding Go slices, their underlying array structure, creation and modification mechanics, and the implications when passing slices to functions.

08

JSON Encoding and Decoding in Go

backendgo

A guide to JSON serialization and deserialization in Go, covering type mappings, HTTP responses, and practical examples with the net/http package.

09

Go Function Argument Passing Behavior

backendgo

How Go passes function arguments by value and the implications for different data types: integers, pointers, slices, strings, and structs.

10

Understanding Interfaces in Go

backendgo

A guide to understand Go interfaces through a power socket and electrical device analogy, covering duck typing and interface implementation.

11

Basic Data Structures in Go

backendgo

Understanding Go data structures and their memory layout including integers, floats, arrays, pointers, structs, strings, and slices.

12

Indexing Strings and Runes in Go

backendgo

Understanding the difference between indexing strings as bytes versus runes in Go, and when to use each approach for proper Unicode handling.

13

The io.Reader and io.Writer Interfaces in Go

backendgo

Understanding the io.Reader and io.Writer interfaces in Go, and how accepting an io.Writer parameter makes your code flexible across files, HTTP responses, stdout, and in-memory buffers.

14

Self-Hosting a Go Binary on AWS EC2

backendgoaws

Deploying a Go service to a single AWS EC2 instance as a hardened systemd service - cross-compiling the binary, copying it across, creating a non-root service user, configuring systemd with the right hardening directives, and handling graceful shutdown.