A goroutine is a super-cheap worker you start with go doThing(). Channels are pipes workers use to pass data safely to each other: “don’t share memory, communicate”.
results := make(chan int)
for _, url := range urls {
go func(u string) { results <- fetchSize(u) }(url)
}
total := 0
for range urls { total += <-results }
Say it like this in the interview
“Goroutines are lightweight, runtime-scheduled threads costing a few KB each. Channels synchronise and pass data between them. I use sync.WaitGroup to wait for groups, errgroup when errors matter, and context for cancellation.”
Several workers read the same old value and write back, overwriting each other. It’s a data race.
Say it like this in the interview
“Unsynchronised concurrent writes. Fix with sync.Mutex, atomic.Int64, or channel ownership. Detect with go test -race or go run -race, which I run in CI.”
It’s a cancel button and deadline passed down through every function handling a request. If the user disconnects or time runs out, all the work underneath stops.
Say it like this in the interview
“Context carries cancellation, deadlines and request-scoped values across API boundaries. It’s the first parameter of functions doing I/O; I set timeouts with context.WithTimeout and always call the cancel function. I don’t use it for optional parameters.”
Go’s normal maps aren’t safe to write from several goroutines at once.
Say it like this in the interview
“Concurrent map access without synchronisation. Protect with sync.RWMutex, use sync.Map for specific access patterns, or confine the map to one goroutine that receives updates via channels.”
No exceptions: functions return an error as a normal value, and you check it right away.
user, err := repo.Find(ctx, id)
if err != nil {
return fmt.Errorf("find user %d: %w", id, err)
}
if errors.Is(err, sql.ErrNoRows) { /* not found */ }
Say it like this in the interview
“Errors are values returned alongside results. I wrap them with %w for context and check with errors.Is and errors.As. panic is only for truly unrecoverable situations.”
a := []int{1, 2, 3}
b := a[:2]
b = append(b, 99)
fmt.Println(a)
In simple words
A slice is a window onto an underlying array. b shares a’s array and still has room (capacity 3), so append writes into position 2 of the shared array, overwriting the 3.
Say it like this in the interview
“[1 2 99]. b shares the backing array and has spare capacity, so append overwrites a[2]. To avoid it, copy the slice or use a full slice expression a[:2:2] to limit capacity.”
In Go, you never write “implements”. If a type has the methods an interface asks for, it automatically satisfies it.
Say it like this in the interview
“Interfaces are satisfied implicitly, which encourages small interfaces like io.Reader defined by the consumer. Accept interfaces, return concrete types.”
func main() {
for i := 1; i <= 3; i++ {
defer fmt.Print(i, " ")
}
}
In simple words
defer schedules a call for when the function returns. Deferred calls run in reverse order (last in, first out).
Say it like this in the interview
“3 2 1. Each iteration defers a print, and deferred calls run last-in-first-out when main returns. The argument i is evaluated when the defer statement runs, so each call keeps its own value.”
“net/http with the Go 1.22+ method and pattern routing, encoding JSON with json.NewEncoder, and setting the content type. Timeouts set on http.Server.”