1---2name: build-reliable-backend-services3description: "Build reliable backend services with proper error handling, security, and observability."4category: "DevOps & Infra"5author: community6version: "1.0.0"7icon: server8metadata:9 source: https://skillmd.com/skills/rondoflow/build-reliable-backend-services10---1112## Error Handling1314- Never expose stack traces to clients—log internally, return generic message15- Structured error responses: code, message, request ID—enables debugging without leaking16- Fail fast on bad input—validate at entry point, not deep in business logic17- Unexpected errors: 500 + alert—expected errors: appropriate 4xx1819## Input Validation2021- Validate everything from outside—query params, headers, body, path params22- Whitelist valid input, don't blacklist bad—reject unknown fields23- Validate early, before any processing—save resources, clearer errors24- Size limits on all inputs—prevent memory exhaustion attacks2526## Timeouts Everywhere2728- Database queries: set timeout, typically 5-30s29- External HTTP calls: connect timeout + read timeout—don't wait forever30- Overall request timeout—gateway or middleware level31- Background jobs: max execution time—prevent zombie processes3233## Retry Patterns3435- Exponential backoff: 1s, 2s, 4s, 8s...—prevents thundering herd36- Add jitter: randomize delay—prevents synchronized retries37- Idempotency keys for non-idempotent operations—safe to retry38- Circuit breaker for failing dependencies—stop hammering, fail fast3940## Database Practices4142- Connection pooling: reuse connections—creating is expensive43- Transactions scoped minimal—hold locks briefly44- Read replicas for read-heavy workloads—separate read/write traffic45- Prepared statements always—SQL injection prevention, query plan cache4647## Caching Strategy4849- Cache invalidation strategy decided upfront—TTL, event-based, or both50- Cache at right layer: query result, computed value, HTTP response51- Cache stampede prevention—lock or probabilistic early expiration52- Monitor hit rate—low hit rate = wasted resources5354## Rate Limiting5556- Per-user/IP limits on expensive operations—login, signup, search57- Different limits for different operations—read vs write58- Return Retry-After header—tell clients when to retry59- Rate limit early in request pipeline—save resources6061## Health Checks6263- Liveness: is process running—restart if fails64- Readiness: can handle traffic—remove from load balancer if fails65- Startup probe for slow-starting services—don't kill during init66- Health checks fast and cheap—don't hit database on every probe6768## Graceful Shutdown6970- Stop accepting new requests first—drain load balancer71- Wait for in-flight requests to complete—with timeout72- Close database connections cleanly—prevent connection leaks73- SIGTERM handling: graceful; SIGKILL after timeout7475## Logging7677- Structured logs (JSON)—parseable by log aggregators78- Request ID in every log—trace request across services79- Log level appropriate: debug for dev, info/error for prod80- Sensitive data never logged—passwords, tokens, PII8182## API Design8384- Versioning strategy from day one—path (/v1/) or header85- Pagination for list endpoints—cursor or offset; include total count86- Consistent response format—same envelope everywhere87- Meaningful status codes—201 for create, 204 for delete, 404 for not found8889## Security Hygiene9091- Secrets from environment or vault—never in code or config files92- Dependencies updated regularly—automated with Dependabot/Renovate93- Principle of least privilege—service accounts with minimal permissions94- Authentication and authorization separated—who you are vs what you can do9596## Observability9798- Metrics: request count, latency percentiles, error rate—the RED method99- Distributed tracing for microservices—follow request across services100- Alerting on symptoms, not causes—high error rate, not CPU usage101- Dashboards for operational visibility—know normal to spot abnormal