A lightweight Fiber API
Wire one fast, explicit application boundary.
The idea
Fiber provides routing and middleware on fasthttp. Keep handlers small: read and validate input, call the use case, then return a response. Construct shared dependencies once at startup. Compile one binary and let systemd supervise its lifecycle; use graceful shutdown to drain in-flight work.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
app := fiber.New(fiber.Config{
AppName: "Booking API",
ReadTimeout: 10 * time.Second,
WriteTimeout: 15 * time.Second,
BodyLimit: 64 * 1024,
})
app.Get("/healthz", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"status": "ok"})
})Decisions that matter
- Use Fiber-native routing and middleware consistently.
- Request contexts are pooled and must not escape their lifetime.
- Performance decisions need workload measurements, not framework labels alone.
Your turn
Where should the pgx pool live, and should a handler create a pool on every request?
Reveal a worked answer
Create one bounded pool at startup, inject the store into handlers, and close it after the service drains. Creating pools per request multiplies connections and discards reuse. Verify database readiness before declaring the app available.