Backend Roadmap
What you will learn
By the end of this lesson, you will be able to:
- identify the main boundaries in a backend service;
- separate transport, business, and storage concerns;
- explain why production readiness includes more than endpoint code;
- plan a service in vertical slices;
- choose a sensible order for the remaining backend lessons.
Mental model: a backend is a long-running coordinator
A backend accepts work from outside the process, validates it, applies business rules, reads or changes state, and returns a result. It must keep doing that while requests overlap, dependencies fail, deployments replace the process, and invalid or hostile input arrives.
The HTTP handler is only the outer edge.
client
↓
HTTP transport
↓
application service
↓
repository or external client
↓
database / remote service
Cross-cutting concerns surround the flow:
- configuration;
- logging, metrics, and tracing;
- authentication and authorization;
- cancellation and timeouts;
- graceful startup and shutdown;
- tests and security checks.
Start with one vertical slice
Do not create dozens of empty packages before implementing a feature. Begin with one small use case, such as creating and listing lessons:
POST /lessons
GET /lessons
Implement the complete path:
- Parse the request.
- Validate its shape.
- Apply business rules.
- Store or retrieve data.
- Map the result to an HTTP response.
- Test success and failure.
Then extract boundaries that have demonstrated a reason to exist.
A practical package shape
cmd/api/main.go
internal/
lesson/
lesson.go
service.go
repository.go
httpapi/
routes.go
lessons.go
middleware.go
postgres/
lessons.go
This is an example, not a required standard.
cmd/apiwires dependencies and owns process lifetime.lessoncontains domain concepts and use cases.httpapitranslates HTTP into application calls.postgresimplements storage details.
Keep package names short, concrete, and based on responsibility. Avoid catch-all packages named utils, common, or helpers when a more specific home exists.
Dependency direction
Inner application code should not need to know HTTP status codes or SQL driver details.
type LessonRepository interface {
Create(ctx context.Context, lesson Lesson) error
List(ctx context.Context) ([]Lesson, error)
}
type Service struct {
repository LessonRepository
}
The service declares the behaviour it needs. A database adapter implements that behaviour. The command chooses the implementation and connects them.
Do not create an interface automatically for every struct. Add one at a consumer boundary when multiple implementations, testing isolation, or architectural separation provides real value.
Production questions to answer
Before calling a service production-ready, ask:
- How are timeouts set at the server, request, database, and external-client levels?
- What happens when the client disconnects?
- Which operations can be retried safely?
- How are secrets provided and protected?
- What is logged, measured, and traced?
- How does the process signal readiness and health?
- How are schema changes deployed?
- How does shutdown stop new work and drain current work?
- How can a failed release be rolled back?
These are design inputs, not cleanup tasks for the final day.
Learning sequence
Follow this section in order:
- HTTP API design
- Middleware
- Validation
- Application wiring and configuration
- Observability
database/sql- Transactions
- Authentication and authorization
- Graceful shutdown
- Production checklist
Common mistakes
- Beginning with a framework: framework knowledge cannot replace understanding HTTP, context, ownership, and errors.
- Designing every future layer first: unused abstractions make change harder.
- Letting handlers contain all business logic: reuse and focused testing become difficult.
- Passing database rows directly to clients: storage schema changes become API changes.
- Calling a service production-ready because it starts: operability and safe failure are part of correctness.
Practice
Sketch the request path for creating a lesson. Name the data type at each boundary, which layer validates it, which layer owns the business rule, and how cancellation reaches storage.
HTTP JSON CreateLessonRequest
↓ decode + shape validation in HTTP transport
application CreateLessonCommand
↓ business validation in lesson service
domain Lesson
↓ repository interface receives request context
database INSERT parameters
↓ generated ID returned upward
HTTP LessonResponse + 201 Created
The request's context is passed from the handler to the service and repository. HTTP-specific details stay in the transport. Business rules such as title uniqueness belong in the application/domain boundary. Database constraints still enforce critical invariants because concurrent requests can pass an application check at the same time.
Summary
- A backend coordinates transport, application rules, storage, and operations.
- Build one complete vertical slice before introducing many abstractions.
- Keep HTTP and SQL details out of core business rules.
- Interfaces belong at useful consumer boundaries, not everywhere.
- Production behaviour includes cancellation, security, observability, and lifecycle management.
Ready to wrap up?
Mark this complete when you can explain the main idea and finish the practice task.