A production-like REST API infrastructure built with Go and PostgreSQL, featuring Docker, Nginx, CI/CD, monitoring, centralized logging, and alerting.
┌───────────────┐
│ Internet │
└───────┬───────┘
│
▼
┌───────────────┐
│ Nginx │
└───────┬───────┘
│
▼
┌───────────────┐
│ Book API │
│ Go │
└───────┬───────┘
│
▼
┌───────────────┐
│ PostgreSQL │
└───────────────┘
┌─────────────────────────────────────────┐
│ Reliability │
│ │
│ PostgreSQL ──► Backup / Restore │
│ Docker ──────► Health Checks │
│ Go API ──────► Graceful Shutdown │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ Observability │
│ │
│ Prometheus ──► Grafana │
│ Node Exporter ─► Grafana │
│ Promtail ──► Loki ──► Grafana │
│ Prometheus ──► Alertmanager │
└─────────────────────────────────────────┘
This repository demonstrates the evolution of a backend service into a production-like infrastructure.
The project gradually grows from a simple REST API into a reliable, observable, and automated platform featuring monitoring, centralized logging, infrastructure automation, Kubernetes, and GitOps.
- REST API
- PostgreSQL
- Docker
- Docker Compose
- Nginx
- HTTPS
- CI/CD
- Prometheus
- Application metrics
- Grafana
- Application dashboard
- Server dashboard
- Node Exporter
- Loki
- Promtail
- Alertmanager
- Alert rules
- Grafana provisioning
- Automated PostgreSQL Backup
- PostgreSQL Restore
- Health Checks
- Graceful Shutdown
- Failure Tests
- Ansible
- Infrastructure automation
- k3s
- Helm
- Ingress
- Cert-Manager
- Readiness / Liveness Probes
- Rolling Updates
- HPA
- Persistent Volumes
- ArgoCD
- Canary
- Rollback
- Go
- PostgreSQL
- Docker
- Docker Compose
- Nginx
- Ansible
- Prometheus
- Grafana
- Node Exporter
- Loki
- Promtail
- Alertmanager
- PostgreSQL Backup / Restore
- Docker Health Checks
- Graceful Shutdown
The application exposes Prometheus metrics through:
/metrics
Application metrics include:
- HTTP requests
- HTTP errors
- HTTP request duration
- Books created
- Books returned
- Database queries
Grafana provides separate dashboards for:
- Application
- Server
Loki and Promtail provide centralized collection and visualization of Docker container logs.
Alertmanager handles alerts generated by Prometheus.
The project includes reliability mechanisms for backup, service health monitoring, and graceful application shutdown.
PostgreSQL backups are created automatically using pg_dump and scheduled with cron.
Backups can be restored to a separate PostgreSQL database for verification.
Docker health checks are configured for the application and infrastructure services.
The Go API exposes:
/health
The Go HTTP server handles SIGTERM and SIGINT signals.
During shutdown:
- New HTTP requests are no longer accepted.
- Active requests are allowed to finish.
- PostgreSQL connections are closed.
- The application process exits.
- Docker
- Docker Compose
-
Clone the repository.
-
Copy the environment template:
cp .env.example .env- Start the application:
docker compose up --buildThe API will be available at:
http://localhost
Grafana:
http://localhost:3000
Prometheus:
http://localhost:9090
Alertmanager:
http://localhost:9093
The project uses the following environment variables:
| Variable | Description |
|---|---|
DB_HOST |
PostgreSQL host |
DB_PORT |
PostgreSQL port |
DB_USER |
PostgreSQL username |
DB_PASSWORD |
PostgreSQL password |
DB_NAME |
PostgreSQL database name |
See .env.example for default values.
The project uses Ansible to automate VPS provisioning and application deployment.
The playbook (ansible/playbook.yml) performs the following on a fresh Ubuntu server:
- Installs system dependencies (ca-certificates, curl, git).
- Installs Docker Engine and Docker Compose plugin.
- Creates a
deployuser with Docker access. - Adds your SSH public key for the
deployuser. - Clones the repository from GitHub.
- Generates the
.envfile from a Jinja2 template. - Pulls the latest Docker images.
- Starts the application stack with
docker compose up -d.
# Edit ansible/vars.yml to set your SSH key and DB credentials
# Then run:
ansible-playbook -i ansible/inventory.ini ansible/playbook.ymlThe inventory targets a single production host (prod) at 104.252.127.239.
.
├── alertmanager/
│ └── alertmanager.yml
├── ansible/
│ ├── inventory.ini
│ ├── playbook.yml
│ ├── templates/
│ │ └── .env.j2
│ └── vars.yml
├── db/
│ └── init.sql
├── grafana/
│ └── provisioning/
│ ├── dashboards/
│ └── datasources/
├── loki/
│ └── loki-config.yml
├── nginx/
│ └── nginx.conf
├── prometheus/
│ ├── prometheus.yml
│ └── alerts.yml
├── promtail/
│ └── promtail-config.yml
├── docker-compose.yml
├── Dockerfile
├── main.go
└── README.md