Skip to content

Infrastructure Overview

OpticWorks uses a multi-cloud infrastructure strategy optimized for performance, cost, and reliability. This page provides an overview of our infrastructure components and how they work together.

┌─────────────────────────────────────────────────────────────────────────────┐
│ OpticWorks Infrastructure │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Cloudflare (Edge Layer) │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────────────┐│ │
│ │ │ Workers │ │ R2 │ │ Images │ │ Access ││ │
│ │ │Storefront │ │ Storage │ │ CDN │ │ (Zero Trust) ││ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────────────┘│ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Hetzner Cloud (Compute Layer) │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────────────┐│ │
│ │ │ Medusa │ │PostgreSQL │ │ Redis │ │ Staging ││ │
│ │ │ API │ │ 17 │ │ 7 │ │ Instances ││ │
│ │ │ (CX21) │ │ (CX31) │ │ (CX11) │ │ ││ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────────────┘│ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Third-Party Services │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────────────┐│ │
│ │ │ Stripe │ │ EasyPost │ │ Resend │ │ Hookdeck ││ │
│ │ │ Payments │ │ Shipping │ │ Email │ │ Webhooks ││ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────────────┘│ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Internal Services │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────────────┐│ │
│ │ │ Infisical │ │ GitHub │ │ PagerDuty │ │ Grafana ││ │
│ │ │ Secrets │ │ Actions │ │ Alerts │ │ Monitoring ││ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────────────┘│ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

We use Cloudflare as our edge layer for CDN, compute, and security.

ApplicationPurposeURL
StorefrontNext.js e-commerce frontendoptic.works
IntranetInternal documentationintranet.optic.works
API GatewayRate limiting & routingapi-edge.optic.works

Why Workers?

  • Global edge deployment (sub-50ms latency worldwide)
  • Zero cold starts
  • Integrated with other Cloudflare services
  • Cost-effective for our traffic patterns
BucketPurposeAccess
opticworks-assetsProduct images, static assetsPublic (CDN)
opticworks-backupsDatabase backupsPrivate
opticworks-firmwareFirmware binariesPrivate (signed URLs)
opticworks-intranetIntranet static siteCloudflare Access

R2 vs S3:

  • No egress fees (major cost savings)
  • S3-compatible API
  • Integrated with Workers

Protects internal applications without VPN:

ApplicationAuth MethodAccess
IntranetGoogle Workspace@optic.works emails
Admin DashboardGoogle Workspace + MFAEngineering team
GrafanaGoogle WorkspacePlatform team

Setup:

  1. Access is enforced at Cloudflare edge
  2. Users authenticate via Google Workspace
  3. Session tokens are validated on each request
  • Automatic image optimization
  • WebP/AVIF conversion
  • Responsive variants
  • Used for product images on optic.works

Our primary compute provider for backend services.

FactorHetznerAWS/GCP
Cost~70% cheaperBaseline
PerformanceExcellent (AMD EPYC)Excellent
EU Data ResidencyYes (Germany)Complex
SimplicityVery simpleComplex
ServerSpecPurposeLocation
medusa-prod-1CX21 (2 vCPU, 4GB)Medusa APIFalkenstein
db-prod-1CX31 (4 vCPU, 8GB)PostgreSQL 17Falkenstein
redis-prod-1CX11 (1 vCPU, 2GB)Redis 7Falkenstein
medusa-stagingCX11 (1 vCPU, 2GB)Staging environmentFalkenstein
Terminal window
# SSH access (requires VPN or Cloudflare WARP)
ssh deploy@medusa-prod-1.optic.works
# SSH config (~/.ssh/config)
Host *.optic.works
User deploy
IdentityFile ~/.ssh/opticworks
ProxyJump bastion.optic.works
  • Private network between all servers (10.0.0.0/24)
  • Firewall rules managed via Hetzner Cloud Console
  • External access only via bastion or Cloudflare Tunnel

Production:

  • Server: db-prod-1 (CX31)
  • Daily automated backups to R2
  • Point-in-time recovery enabled
  • Connection pooling via PgBouncer

Connection:

Terminal window
# Via bastion (production)
psql -h db-prod-1.internal -U medusa -d medusa_production
# Direct (staging only)
psql -h db-staging.optic.works -U medusa -d medusa_staging

Used for:

  • Session storage
  • API rate limiting
  • Background job queues
  • Cache layer

Connection:

Terminal window
redis-cli -h redis-prod-1.internal -p 6379

All secrets are stored and managed in Infisical. See Infisical Guide for detailed usage.

Key Points:

  • No secrets in git repositories
  • Environment-specific secret sets
  • Automatic rotation for critical credentials
  • Audit logging for compliance

All repositories use GitHub Actions for CI/CD:

WorkflowTriggerActions
ci.ymlPR openedLint, test, build
deploy-staging.ymlPush to developDeploy to staging
deploy-production.ymlPush to mainDeploy to production
backup.ymlDaily scheduleDatabase backup

Self-Hosted Runners:

  • Located on N100 nodes in the office
  • Used for hardware testing (RS-1, ESP32)
  • Faster builds for large projects
Developer Push
GitHub Actions
├─── Lint & Test
├─── Build Artifacts
├─── Deploy to Staging
│ │
│ ▼
│ Staging Tests
└─── Deploy to Production
Health Checks
  • URL: grafana.optic.works
  • Access: Platform team via Cloudflare Access
  • Dashboards: API performance, database metrics, infrastructure
  • Critical alerts: API errors, database issues, payment failures
  • Warning alerts: High latency, disk usage
  • On-call rotation: Weekly, see #ops-oncall channel
  • Cloudflare health checks for all public endpoints
  • Internal health endpoints at /health on each service
  • Slack notifications for status changes
Internet
┌─────────────────┐
│ Cloudflare │
│ (WAF + CDN) │
└────────┬────────┘
┌─────────────┴─────────────┐
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Cloudflare │ │ Hetzner │
│ Workers │ │ (via Tunnel) │
│ (Storefront) │ │ │
└─────────────────┘ └────────┬────────┘
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Medusa │ │PostgreSQL│ │ Redis │
│ API │ │ │ │ │
└──────────┘ └──────────┘ └──────────┘
│ Private Network
│ (10.0.0.0/24)
ServiceMonthly CostPurpose
Hetzner Cloud~$50Compute, databases
Cloudflare~$25Workers, R2, Access
GitHub$21/userRepository hosting
Infisical$18/userSecret management
PagerDuty~$30Alerting
Total~$150 + per-user
Need Access ToRequest ViaApprover
Hetzner Cloud ConsoleIT TicketPlatform Lead
Cloudflare DashboardIT TicketPlatform Lead
Production SSHIT TicketEngineering Lead
GrafanaAutomatic(Cloudflare Access)