back to projects
Architecture: apps → otpd (Go) → Redis, SMTP and Prometheus
Backend · Microservice·Creator · backend·2026

OTP Service

A Go microservice that generates, e-mails and verifies one-time codes for my projects.

Go + RedisHMAC + pepperRate limit + metrics

A reusable service for e-mail verification, login codes and password-reset links, shared across personal projects (My Market List uses it in production). Each project has its own API keys, sender, locale, rate limits and purposes (signup, login, reset_password, change_email), each with its own kind (6-digit code or link token), TTL, max attempts and cooldown. It ships with HTML + text templates in pt-BR and en, OpenAPI docs, ADRs, health checks, Prometheus metrics, Docker Compose for local dev and a Render deploy.

// challenge

Codes are short (10⁶ combinations), so the service must resist brute force and leaks — and stay correct under concurrent requests — while remaining simple to plug into any backend.

// solution

Hexagonal architecture with a pure domain; codes generated with crypto/rand and stored only as HMAC-SHA256 with a secret pepper; atomic Redis operations via Lua scripts; fixed-window rate limiting per e-mail, IP and project with Retry-After; an in-memory e-mail queue with graceful shutdown; and a stable error contract (RFC 7807).

// result

One service that all my apps reuse for verification flows, covered by unit tests with -race, Redis integration tests via testcontainers, lint and govulncheck in CI.

// stack
GoRedisDockerPrometheusOpenAPIGitHub Actions
// gallery
Architecture: apps → otpd (Go) → Redis, SMTP and Prometheus
Architecture: apps → otpd (Go) → Redis, SMTP and Prometheus
API flow: send, verify and rate limit (demo)
API flow: send, verify and rate limit (demo)
Code e-mail rendered from the templates (demo)
Code e-mail rendered from the templates (demo)
Endpoints, architecture decisions and metrics (demo)
Endpoints, architecture decisions and metrics (demo)
open in terminal:open otp-service
OTP Service — Eduardo Souza