Makefile, golangci-lint and Docker Compose

The three files that make a backend repo repeatable: a Makefile of short commands, a golangci-lint config that catches bugs before review, and a docker-compose.yml that starts MySQL and Redis with one command.

Learning outcomes

  • Write a Makefile with phony targets for lint, test, up and down.
  • Explain what a linter checks and configure golangci-lint v2 with a small set of useful linters.
  • Read and write a docker-compose.yml with services, ports, environment, volumes and health checks.
  • Start and stop local MySQL and Redis with docker compose, and open a client inside a container.
Prerequisite conceptsGo modules

What you will learn

A Go project needs more than source code to be easy to build, test, and maintain. As the backend grows, you will need a consistent way to run common commands, catch mistakes before they reach production, and start the infrastructure that your application depends on.

You will set up three tools that solve these problems:

  • A Makefile that provides short, repeatable commands for common development tasks.
  • golangci-lint, which runs multiple static analysis checks against your Go code.
  • Docker Compose, which starts and manages the local services required by the backend.

All three configuration files live inside backend/, next to go.mod. This is intentional: backend/ is the Go module root, and its development configuration belongs alongside the module.

By the end of this lesson, you will understand:

  • Why a Makefile is useful and how Make targets work.
  • The difference between compilation, go vet, and linting.
  • How to configure golangci-lint v2.
  • How Docker Compose defines and manages multiple services.
  • How environment variables configure local services.
  • How to start, inspect, and stop the local development environment.
  • Common mistakes that cause development commands or services to fail.

1. The backend development environment

Before building application features, establish a reliable development environment.

A backend is rarely a single executable that runs without dependencies. It usually needs a database, a cache, and sometimes a message broker. Developers also need tools to format code, run tests, and identify potential bugs.

Without a consistent setup, each developer ends up maintaining their own collection of commands and local configuration. That creates unnecessary differences between machines.

For this course, the backend lives in a Go module named github.com/yashdagar/zomato-prep/backend.

The repository has a simple structure at this stage:

  • zomato-prep/
    • backend/
      • go.mod
      • go.sum
      • Makefile
      • .golangci.yml
      • docker-compose.yml
      • cmd/
      • internal/
      • tools/
    • The application will be added at the repository root later.

The important distinction is that the repository root and the Go module root are not the same directory.

zomato-prep/ is the repository root. zomato-prep/backend/ is the Go module root.

The Makefile, linter configuration, and Docker Compose configuration all belong in backend/, next to go.mod.

Throughout this lesson, commands are run from backend/. Start from the repository root and enter the module directory:

bash
cd backend

Verify that you are in the correct directory:

bash
pwd
ls

You should see go.mod in the current directory. If you do not, stop and locate the backend module before continuing.

This matters because tools such as Go, Make, and Docker Compose use the current working directory to discover configuration files.

2. Makefiles: repeatable development commands

The problem with remembering commands

Consider the commands you might run during development:

bash
go test ./...
go test -race ./...
go run ./cmd/api
golangci-lint run
docker compose up -d
docker compose down

Each command has a purpose, but remembering every command and its exact arguments becomes inconvenient.

The problem gets worse when commands need additional parameters.

For example, the course has a test runner that selects tests for a particular exercise. You might need to remember its location, arguments, and the correct working directory.

You could document all these commands in a README, but that still requires developers to copy and paste them correctly.

A Makefile solves this by giving common operations short names.

Instead of remembering:

bash
go test ./...

you can run:

bash
make unit

Instead of remembering how to start the local services:

bash
docker compose up -d

you can run:

bash
make up

The Makefile becomes the standard command interface for the backend.

How Make works

Make is a build automation tool. It reads a file named Makefile and executes recipes associated with named targets.

A simple target looks like this:

makefile
run:
	go run ./cmd/api

There are two important parts:

  • run is the target name.
  • The indented command is the recipe Make executes.

When you execute:

bash
make run

Make looks for the run target and executes its recipe.

A target does not have to compile a program. It can represent any repeatable operation, such as running tests, checking code, or starting services.

Make is often associated with compiling C and C++ programs, but it is equally useful for Go projects. It provides a consistent interface regardless of the language or underlying command.

Where the Makefile belongs

Create the file at:

zomato-prep/backend/Makefile

Do not place it at the repository root.

You should be able to see the Makefile and go.mod in the same directory:

  • backend/
    • go.mod
    • go.sum
    • Makefile

Make discovers a file named Makefile in the current directory. Therefore, all the Make commands in this course are executed from backend/.

The project's Makefile

The backend uses six targets:

TargetPurpose
lintRun golangci-lint against the backend
testRun the course test runner for a selected exercise
unitRun the Go unit tests
runStart the API server
upStart local infrastructure services
downStop local infrastructure services

Create zomato-prep/backend/Makefile with the following content:

makefile
.PHONY: lint test unit run up down

lint:
	golangci-lint run

test:
	go run ./tools/zt test $(W) $(if $(V),-v)

unit:
	go test ./...

run:
	go run ./cmd/api

up:
	docker compose up -d

down:
	docker compose down

Let's understand each target.

lint

makefile
lint:
	golangci-lint run

Runs the configured linter against the Go code in the module.

You do not need to remember the exact linter command every time. Run:

bash
make lint

test

makefile
test:
	go run ./tools/zt test $(W) $(if $(V),-v)

This target uses the course's test runner.

The W variable identifies the exercise whose tests should run. For example:

bash
make test W=1B2

This selects the tests for exercise 1B2.

The V variable controls verbose output:

bash
make test W=1B2 V=1

The expression $(if $(V),-v) is Make's conditional variable expansion. If V is non-empty, Make includes -v in the command. Otherwise, it includes nothing.

This gives you one target that supports both normal and verbose test execution.

unit

makefile
unit:
	go test ./...

Runs the Go test suite across all packages in the module.

The ./... pattern tells the Go tool to include the current package and packages below it.

run

makefile
run:
	go run ./cmd/api

Starts the API executable.

This target becomes useful once the API server is implemented.

up and down

makefile
up:
	docker compose up -d

down:
	docker compose down

These targets start and stop the local infrastructure services defined in the Compose file.

Why .PHONY matters

You may have noticed this line:

makefile
.PHONY: lint test unit run up down

Make normally treats targets as file targets.

For example, if a file named lint exists in the current directory and Make determines that it is up to date, it may skip the recipe for that target.

That is not what we want. lint represents an operation, not a file that needs to be generated.

.PHONY tells Make that these targets are commands and should not be treated as ordinary file targets.

For command-oriented Makefiles, declaring the targets as phony is a good default.

Make's tab requirement

There is one particularly common Makefile mistake.

Recipe lines must begin with a tab character.

This is valid:

makefile
run:
	go run ./cmd/api

This can fail:

makefile
run:
    go run ./cmd/api

The second example uses spaces instead of a tab. Make may report:

Makefile:2: *** missing separator. Stop.

If you encounter this error, inspect the indentation of your recipe lines.

Running the Makefile

Make sure you are in backend/:

bash
pwd

Then try:

bash
make

If the Makefile does not define a default target, Make may execute the first target. In this file, that is lint.

You can also run each target explicitly:

bash
make lint
make test W=1B2
make test W=1B2 V=1
make unit
make run
make up
make down

Some targets depend on tools or application code that will be introduced later. It is normal for a target to fail before its required executable, source code, or service has been added.

The important point is that the command interface is now defined in one place.

3. Go code quality: compiler, go vet, and linting

A Go program can compile successfully and still contain mistakes.

Compilation is essential, but it does not prove that the code is correct, easy to maintain, or free from suspicious patterns.

Go development commonly uses three layers of checks:

  1. The Go compiler.
  2. go vet.
  3. A linter such as golangci-lint.

These tools overlap in some areas, but they have different responsibilities.

The compiler

The Go compiler checks whether your source code can be translated into an executable program.

It catches errors such as:

  • Invalid syntax.
  • Undefined variables.
  • Missing imports.
  • Type mismatches.
  • Invalid function calls.
  • Incorrect use of language constructs.

For example:

go
package main

func main() {
	var count int
	count = "five"
}

This program does not compile because a string cannot be assigned to an integer variable.

The compiler rejects the program before it can run.

Compilation is therefore the first correctness gate. If your code does not compile, you cannot meaningfully execute its tests.

However, compilation does not catch every suspicious programming pattern.

go vet

go vet is a static analysis tool included with the Go toolchain.

It examines Go source code and reports suspicious constructs that may indicate bugs.

For example, consider a formatting mistake:

go
package main

import "fmt"

func main() {
	name := "Priya"
	fmt.Printf("%d\n", name)
}

The program may compile, but %d is intended for integer formatting. Passing a string is suspicious.

go vet can detect this mismatch.

Run it from backend/:

bash
go vet ./...

The ./... pattern checks all packages in the module.

go vet does not execute your application. It inspects the source code and reports issues it can identify through static analysis.

It is useful because many mistakes are not syntax errors or type errors, but still indicate that the program may not behave as intended.

Linting

Linting goes further by applying a collection of static checks and coding rules.

A linter can identify issues such as:

  • Ignored errors.
  • Unused assignments.
  • Unnecessary code.
  • Suspicious control flow.
  • Poorly structured code.
  • Potential correctness problems.
  • Formatting inconsistencies.

Go has several independent linters. Running each one manually would be inconvenient.

golangci-lint coordinates multiple linters and analyzers through a single command and configuration file.

It includes checks that overlap with go vet, but it also provides a broader collection of analysis tools.

Comparing the three

ToolMain responsibilityExample
CompilerCheck whether code is valid GoReject assigning a string to an integer
go vetIdentify suspicious Go constructsDetect incorrect formatting directives
golangci-lintRun multiple code quality checksDetect ignored errors and ineffective assignments

These checks complement each other.

A useful way to think about them:

  • The compiler checks whether the program can be built.
  • go vet checks for suspicious patterns.
  • The linter applies a broader set of code quality checks.

Passing all three does not guarantee that your program is correct. Tests are still necessary to verify actual behavior.

Why not just use go vet?

You should still use go vet.

The point is not to replace it with a linter. The point is to avoid limiting your static analysis to one tool.

For example, errcheck can identify function calls whose returned errors are ignored. staticcheck performs additional checks for common mistakes and questionable code patterns. ineffassign detects assignments that do not affect the program's behavior.

These checks provide useful feedback beyond ordinary compilation.

In this course, golangci-lint provides a consistent way to run the configured checks.

4. Configuring golangci-lint v2

Installing golangci-lint

golangci-lint is an external development tool. It is not part of the Go standard library and is not imported by your application.

Install it using the official installation instructions for your operating system.

After installation, enter backend/ and check that the executable is available:

bash
golangci-lint version

If your terminal reports that the command cannot be found, the executable is either not installed or not available through your PATH.

The PATH environment variable tells your operating system where to look for executable programs.

You should resolve installation issues before continuing.

Why configuration matters

Running a linter without configuration is possible, but a shared project needs consistent rules.

Imagine two developers working on the same backend:

  • One enables checks for ignored errors.
  • Another disables them.
  • One runs formatting checks.
  • Another does not.
  • One uses a five-minute timeout.
  • Another uses a different configuration.

The same source code could produce different results on different machines.

A configuration file gives everyone the same baseline.

The configuration for this course lives at:

zomato-prep/backend/.golangci.yml

It is next to go.mod, not at the repository root.

golangci-lint v2 configuration

golangci-lint v2 uses a versioned configuration format. Its configuration structure differs from older v1 examples.

Create zomato-prep/backend/.golangci.yml:

yaml
version: "2"

run:
  timeout: 5m

linters:
  default: standard
  enable:
    - errcheck
    - govet
    - ineffassign
    - staticcheck
    - unused

formatters:
  enable:
    - gofmt

Let's examine the important sections.

Configuration version

yaml
version: "2"

This identifies the configuration format as version 2.

Do not copy an old v1 configuration into a v2 project without checking whether the configuration fields are still supported.

Run settings

yaml
run:
  timeout: 5m

This sets a maximum execution time for the linter.

Static analysis can take longer as a project grows. A timeout prevents a lint command from running indefinitely.

Linters

yaml
linters:
  default: standard
  enable:
    - errcheck
    - govet
    - ineffassign
    - staticcheck
    - unused

The linters section controls which analyzers are enabled.

The standard default provides the standard set of linters. The additional entries make the intended checks explicit.

Some of these checks are familiar:

  • errcheck reports function calls where returned errors are not checked.
  • govet runs Go's vet analyzers.
  • ineffassign detects assignments whose values are never used.
  • staticcheck identifies additional correctness and quality issues.
  • unused reports unused code.

A key point is that the configuration is shared by the entire backend module.

You do not need a separate linter configuration for every package.

Formatters

yaml
formatters:
  enable:
    - gofmt

Formatters and linters have different responsibilities.

A formatter changes the presentation of code to follow a consistent style. A linter analyzes code and reports potential problems.

gofmt is the standard Go formatter. It handles indentation, spacing, and other formatting decisions.

You can format a file directly:

bash
gofmt -w main.go

The -w option writes the formatted result back to the file.

To inspect which files are not formatted without modifying them:

bash
gofmt -l .

If this command prints no filenames, the Go files it checked are already formatted.

Running the linter

From backend/, execute:

bash
golangci-lint run

Or use the Makefile:

bash
make lint

The Makefile command is preferable during ordinary development because it is the shared project interface.

When the linter reports an issue, read the diagnostic carefully. It normally identifies the file, line, and check responsible for the message.

Do not automatically disable a linter just because it reports something inconvenient. First understand what it found and whether the code should be corrected.

There are legitimate cases where a rule does not fit a particular piece of code, but suppressions should be deliberate and limited.

Common linter problems

Using the wrong configuration version

A v1 configuration copied into a v2 project may contain fields that are no longer valid.

Check the installed linter version and use the matching configuration format.

Running the linter from the wrong directory

The configuration is stored in backend/.golangci.yml.

Run the linter from backend/ so it discovers the intended configuration and analyzes the correct Go module.

Ignoring errors

Go encourages explicit error handling. Ignoring returned errors is often a real correctness problem.

For example:

go
data, _ := os.ReadFile("config.json")

This discards the error. If the file does not exist or cannot be read, the program continues without knowing why the operation failed.

A linter can identify this pattern.

Treating formatting as optional

Formatting is not merely a personal preference in Go projects. gofmt provides a standard layout that makes code easier to review.

Run formatting before committing changes.

5. Docker and Docker Compose

Why the backend needs external services

The backend will eventually need several infrastructure components.

The course uses:

  • MySQL for persistent relational data.
  • Redis for fast shared state and caching.
  • Redpanda for Kafka-compatible event streaming.

These are separate programs. They are not packages that can simply be imported into Go.

You could install each service directly on your machine, configure its ports, create users, and manage its lifecycle manually.

However, that approach creates several problems:

  • Different developers may install different versions.
  • Local configuration may drift.
  • Services may conflict with existing software.
  • Starting and stopping several services becomes repetitive.
  • Reproducing the environment on another machine becomes harder.

Containers solve much of this problem.

What is a container?

A container packages an application together with the environment needed to run it.

A container image contains the files and configuration required to create a container.

For example:

redis:7-alpine

identifies a Redis image using the Redis 7 release line with an Alpine Linux base.

When Docker starts a container from that image, it creates an isolated runtime environment for the service.

Containers are useful because the same image can be used on different development machines.

They also allow multiple versions of a service to run independently, provided their ports and other resources do not conflict.

What Docker Compose adds

Docker can run individual containers, but an application often needs multiple services.

Docker Compose allows you to describe those services in one YAML file.

The configuration can define:

  • Container images.
  • Port mappings.
  • Environment variables.
  • Startup commands.
  • Volumes.
  • Networks.
  • Health checks.
  • Service dependencies.

Instead of starting MySQL, Redis, and Redpanda individually, you describe them once and use a single command to start the development environment.

Where the Compose file belongs

The backend's Compose configuration lives at:

zomato-prep/backend/docker-compose.yml

It belongs next to go.mod, Makefile, and .golangci.yml.

This is important because Docker Compose normally looks for its Compose file in the current directory.

All Compose commands in this course are run from backend/.

Understanding the Compose file

Create zomato-prep/backend/docker-compose.yml:

yaml
services:
  mysql:
    image: mysql:8.4
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-zomato}
      MYSQL_USER: ${MYSQL_USER:-zomato}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-zomato}
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 3s
      retries: 10

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10

  redpanda:
    image: redpandadata/redpanda:v25.1.1
    command:
      - redpanda
      - start
      - --mode
      - dev-container
      - --smp
      - "1"
      - --memory
      - "1G"
      - --reserve-memory
      - "0M"
      - --overprovisioned
      - --node-id
      - "0"
      - --check=false
    ports:
      - "9092:9092"
      - "9644:9644"

This file defines three services.

Let's understand the configuration rather than treating it as a block of YAML to memorize.

The services section

yaml
services:

This is the top-level section that defines the containers Compose should manage.

Each service has a name. Here, the names are:

  • mysql
  • redis
  • redpanda

These names are used by Docker Compose when you inspect logs or manage individual services.

For example:

bash
docker compose logs redis

MySQL

yaml
mysql:
  image: mysql:8.4

This tells Docker Compose to create a container from the MySQL 8.4 image.

The environment variables configure the initial database and credentials:

yaml
environment:
  MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
  MYSQL_DATABASE: ${MYSQL_DATABASE:-zomato}
  MYSQL_USER: ${MYSQL_USER:-zomato}
  MYSQL_PASSWORD: ${MYSQL_PASSWORD:-zomato}

The syntax:

${VARIABLE:-default}

means that Compose uses the value of VARIABLE if it is set and non-empty. Otherwise, it uses the provided default.

For example:

yaml
MYSQL_DATABASE: ${MYSQL_DATABASE:-zomato}

uses zomato when MYSQL_DATABASE has not been configured.

The default credentials here are for local development only. They are not suitable for a production database.

The port mapping is:

yaml
ports:
  - "3306:3306"

The format is:

HOST_PORT:CONTAINER_PORT

This maps port 3306 on your development machine to port 3306 inside the container.

Your Go application can therefore connect to MySQL through:

127.0.0.1:3306

The health check runs:

yaml
healthcheck:
  test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
  interval: 5s
  timeout: 3s
  retries: 10

It periodically checks whether MySQL responds to the ping command.

A running container does not necessarily mean the database is ready. MySQL may still be initializing its data directory or creating the initial database.

The health check helps distinguish a running container from a service that is ready to respond.

Redis

yaml
redis:
  image: redis:7-alpine

This starts Redis 7 using the Alpine image.

Redis is used for fast in-memory operations. Later in the course, you will use it for rate limiting and other operations that benefit from shared state.

Its port mapping is:

yaml
ports:
  - "6379:6379"

Your application can connect to Redis through:

127.0.0.1:6379

The health check runs:

yaml
healthcheck:
  test: ["CMD", "redis-cli", "ping"]
  interval: 5s
  timeout: 3s
  retries: 10

Redis responds to PING with PONG when it is ready.

You can test this yourself later using redis-cli.

Redpanda

yaml
redpanda:
  image: redpandadata/redpanda:v25.1.1

Redpanda provides a Kafka-compatible event streaming interface.

The course introduces it when the backend begins publishing and consuming asynchronous events.

The command section configures a development-oriented single-node instance:

yaml
command:
  - redpanda
  - start
  - --mode
  - dev-container
  - --smp
  - "1"

The remaining arguments configure memory, reserve memory, overprovisioning, node identity, and startup checks.

This is a local development configuration. It is not intended to represent a production Redpanda cluster.

The exposed ports are:

yaml
ports:
  - "9092:9092"
  - "9644:9644"

Port 9092 is used for Kafka-compatible client connections. Port 9644 exposes Redpanda's administrative HTTP API.

Why health checks matter

Starting a container and having a usable service are two different things.

For example, Docker may report that the MySQL container is running while MySQL is still initializing.

If your API tries to connect immediately, it may receive a connection error.

A health check provides a way to test service readiness.

You can inspect the status of the services with:

bash
docker compose ps

Look for the health status in the output.

Do not assume that docker compose up -d means every service is ready at the exact moment the command returns.

6. Environment variables and local configuration

Environment variables are a common way to configure applications without hardcoding values into source code.

For example, a database connection requires information such as:

  • Database host.
  • Database port.
  • Database name.
  • Username.
  • Password.

Hardcoding these values into Go source code would make it difficult to use different configurations on different machines.

Instead, an application can read configuration from environment variables.

Reading environment variables in Go

The standard library provides os.Getenv:

go
package main

import (
	"fmt"
	"os"
)

func main() {
	host := os.Getenv("DB_HOST")
	fmt.Println(host)
}

If DB_HOST is not set, os.Getenv returns an empty string.

You can provide a default:

go
host := os.Getenv("DB_HOST")
if host == "" {
	host = "127.0.0.1"
}

This allows the application to use a local default while still supporting different environments.

Environment variables in Docker Compose

Docker Compose supports environment variable interpolation in its YAML configuration.

For example:

yaml
MYSQL_DATABASE: ${MYSQL_DATABASE:-zomato}

Compose looks for MYSQL_DATABASE in its environment or its project .env file.

If it is not set, Compose uses zomato.

A .env file is a convenient way to provide local values without editing the Compose file.

For example, you could create backend/.env:

dotenv
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=zomato
MYSQL_USER=zomato
MYSQL_PASSWORD=zomato

The Compose file can then read those values through interpolation.

A .env file is not a Go source file. Compose reads it when it processes the configuration.

Keep local environment files out of version control when they contain credentials or machine-specific configuration. A committed example file can document the expected variable names without containing private values.

Compose environment versus application environment

There are two related but different concepts:

  1. Environment variables used by Docker Compose to substitute values into the Compose configuration.
  2. Environment variables passed into a container so the application inside that container can read them.

For example:

yaml
environment:
  MYSQL_DATABASE: ${MYSQL_DATABASE:-zomato}

Compose first resolves the expression. It then passes the resulting value into the MySQL container as an environment variable.

Your Go API runs directly on your development machine in this course. It reads its own environment variables from the shell in which it was started.

Starting MySQL with environment variables does not automatically configure the Go API with a database connection string. The API must receive its own configuration.

This distinction becomes important when you connect the backend to MySQL, Redis, and Redpanda in later weeks.

Checking Compose configuration

Before starting services, you can ask Compose to parse and render the configuration:

bash
docker compose config

This is useful for identifying invalid YAML, missing variables, and interpolation mistakes.

The output shows the resolved configuration. Be careful when sharing it because resolved environment values may contain credentials.

7. Running the local services

Now that the Compose file exists, start the services.

First, make sure you are in the backend module root:

bash
cd backend

Start the services in the background:

bash
docker compose up -d

The -d flag means detached mode. The containers continue running after the command returns.

You can use the Makefile instead:

bash
make up

Both commands start the services defined in docker-compose.yml.

Inspecting service status

Run:

bash
docker compose ps

This lists the services, their container status, and exposed ports.

You should see the MySQL, Redis, and Redpanda services.

If a service is still starting, give it time and inspect its health status.

Inspecting logs

When a service fails to start or is not responding, logs are usually the first place to look.

To see logs from all services:

bash
docker compose logs

To inspect only Redis:

bash
docker compose logs redis

To follow logs as they arrive:

bash
docker compose logs -f redis

Press Ctrl+C to stop following the logs. This does not stop the container.

You can inspect MySQL or Redpanda in the same way:

bash
docker compose logs mysql
docker compose logs redpanda

Testing Redis

Once Redis is healthy, you can test its connection from your machine.

If redis-cli is installed locally:

bash
redis-cli -h 127.0.0.1 -p 6379 ping

Expected response:

PONG

If you do not have redis-cli installed locally, you can execute it inside the Redis container:

bash
docker compose exec redis redis-cli ping

The response should also be:

PONG

This verifies that the Redis service is responding.

Testing MySQL

If you have a local MySQL client installed, you can connect using the development credentials:

bash
mysql -h 127.0.0.1 -P 3306 -u zomato -p

Enter the configured password when prompted.

You can also execute a command inside the MySQL container:

bash
docker compose exec mysql mysql -u zomato -p

The password is the value configured for MYSQL_PASSWORD.

Once connected, you can inspect the database:

sql
SHOW DATABASES;

You should see the zomato database.

Stopping services

When you finish working, stop the local services:

bash
docker compose down

Or use:

bash
make down

This stops and removes the containers and the default Compose network.

It does not normally remove named volumes. If the Compose configuration later adds persistent volumes, their data can survive a normal down.

Do not use volume removal casually. Removing volumes can delete your local database data.

Starting only one service

You do not always need every service running.

For example, if you are currently working only on Redis functionality, you can start Redis alone:

bash
docker compose up -d redis

You can inspect it with:

bash
docker compose ps redis

This is useful when you want to reduce local resource usage.

However, remember that the API may need other services depending on the feature you are testing.

8. Common mistakes and how to fix them

A development environment is useful only when you can diagnose problems in it.

Here are common issues you may encounter.

Running commands from the repository root

The Makefile, .golangci.yml, and docker-compose.yml all live in backend/.

If you run:

bash
make lint

from zomato-prep/, Make may report that there is no Makefile.

Similarly, Docker Compose may not find the intended Compose file, and the linter may not discover the backend configuration.

Fix: Enter the module root first:

bash
cd backend

Then run the command.

Putting configuration files in the wrong directory

The repository root is not the Go module root.

Do not create these files at zomato-prep/:

  • Makefile
  • .golangci.yml
  • docker-compose.yml

Their correct locations are:

  • zomato-prep/backend/Makefile
  • zomato-prep/backend/.golangci.yml
  • zomato-prep/backend/docker-compose.yml

Keeping the configuration next to go.mod makes the module boundary clear.

Using spaces instead of tabs in Makefile recipes

Make expects recipe lines to begin with a tab.

If you use spaces, you may see:

missing separator

Fix: Replace the leading spaces on recipe lines with actual tab characters.

Make cannot find a target

If you see:

make: *** No rule to make target 'something'. Stop.

Check:

  • Are you in backend/?
  • Does the Makefile contain the requested target?
  • Is the target name spelled correctly?
  • Did you accidentally change the target's indentation or formatting?

Also remember that make test expects the W variable to select an exercise.

For example:

bash
make test W=1B2

golangci-lint is not installed

If your shell reports:

command not found: golangci-lint

the executable is unavailable.

Fix: Install golangci-lint using the official instructions for your operating system, then verify it:

bash
golangci-lint version

If it is installed but still unavailable, check whether its installation directory is included in PATH.

Invalid golangci-lint configuration

golangci-lint v1 and v2 use different configuration formats.

A configuration copied from an older project may contain unsupported fields.

Fix: Confirm that the installed executable uses v2 and that .golangci.yml uses the v2 configuration structure shown in this lesson.

Run:

bash
golangci-lint config verify

If your installed version does not support that command, consult its help output and use the validation command supported by that release.

Docker is not running

If Docker Compose reports that it cannot connect to the Docker daemon, the Docker engine may not be running.

Fix: Start Docker Desktop or the Docker service for your operating system, then retry:

bash
docker compose ps

Port already allocated

Suppose another local process is already using port 6379.

Docker may report an error similar to:

port is already allocated

The same problem can happen with MySQL on 3306 or Redpanda on 9092.

Fix: Identify the process using the port and decide whether to stop it or change the host port mapping.

For example:

yaml
ports:
  - "6380:6379"

This maps host port 6380 to Redis container port 6379.

If you change the host port, remember to update the connection address used by your application and tests.

Container is running but the service is unavailable

A running container does not prove that its application is ready.

MySQL may still be initializing. Redis or Redpanda may also need time to start.

Fix: Inspect the health status and logs:

bash
docker compose ps
docker compose logs mysql
docker compose logs redis
docker compose logs redpanda

Wait for the health check to succeed before assuming that the service is ready.

Environment variables are not being picked up

Compose interpolation uses the environment available to Compose and its project .env file.

If you edit an environment variable but the resolved configuration does not change, check:

  • The variable name.
  • Whether the .env file is in the expected project directory.
  • Whether the shell already has a value for that variable.
  • Whether the Compose expression has a valid default.

Use:

bash
docker compose config

to inspect the resolved configuration.

Be careful not to share its output publicly if it contains passwords.

Data disappears after restarting containers

A container's writable filesystem is not the same as durable database storage.

If a database container is removed without persistent storage configured, its data may be lost.

For persistent local development data, Docker Compose can define named volumes.

This lesson focuses on starting the services. Persistent database storage and migration behavior will be handled as the database portion of the course develops.

Do not assume that removing a container is harmless if it contains data you need.

Forgetting to stop services

Containers continue running in the background after docker compose up -d.

If you forget to stop them, they continue consuming memory and CPU.

Fix: Use:

bash
make down

when you finish working.

You can always start them again with:

bash
make up

9. A repeatable development workflow

You now have a consistent way to manage the backend environment.

A typical development session looks like this.

Step 1: Enter the backend module

bash
cd backend

Step 2: Start the local infrastructure

bash
make up

Step 3: Check service status

bash
docker compose ps

Step 4: Work on a feature

Write code in the appropriate package under internal/ or cmd/.

Step 5: Format your code

bash
gofmt -w .

Step 6: Run the relevant exercise tests

bash
make test W=1B2

Replace 1B2 with the exercise you are currently implementing.

Step 7: Run the linter

bash
make lint

Step 8: Run the unit test suite

bash
make unit

Step 9: Start the API if needed

bash
make run

Step 10: Stop local infrastructure when finished

bash
make down

The workflow is deliberately predictable. You should not need to remember different commands for every feature.

As the backend grows, new targets can be added to the Makefile and new services can be added to the Compose configuration.

The goal is to keep the development environment easy to understand and reproduce.

Knowledge assessment

Question 1 of 4

Where should the Makefile, .golangci.yml, and docker-compose.yml be located in the zomato-prep repository?

Pick an answer, then say how sure you are.

Practical applications

You will use these tools throughout the rest of the course.

  • Exercise 1.3: Create the repository and development environment. You will use the Makefile and Docker Compose configuration to establish the local development environment. The backend's services will be started and stopped through the shared commands.
  • Exercise 1.24: GitHub Actions for lint and race tests on every push. The linter configuration and test commands you established here will become part of the automated CI workflow. GitHub Actions will run linting and tests whenever the relevant backend changes are pushed or a pull request is updated.

The configuration you create in this lesson is not temporary scaffolding. It becomes the foundation for how you build, test, and run the backend throughout the course.

References

Everything above is explained on this page; these are where it comes from (GNU Make, golangci-lint v2, Docker Compose).

Finished Lesson 1.2?