payment-gateway.app Docs
Deployment

Environment Variables Reference

Complete reference for all MPG_ configuration variables for both the Admin Backend and Main Backend.

Environment Variables Reference

All configuration uses the MPG_ prefix, loaded by Viper from environment variables or a .env file.

[!NOTE] Both backends share many variable names (database, cache, logging, OTEL, rate limiting, encryption). Where the variable name is the same, it applies identically to both services unless noted.


Shared Variables (Both Backends)

Server

VariableTypeRequiredDefaultDescription
MPG_ENVstringNoproductionRuntime environment: dev, production, production-cloud

Database (MongoDB)

VariableTypeRequiredDefaultDescription
MPG_DATABASE_URIstringYesMongoDB connection string (e.g., mongodb://user:pass@host:27017/)
MPG_DATABASE_NAMEstringYesMongoDB database name
MPG_DATABASE_MAX_POOL_SIZEintNo100Maximum connection pool size
MPG_DATABASE_MIN_POOL_SIZEintNo10Minimum connection pool size
MPG_DATABASE_MAX_CONN_IDLE_TIMEdurationNo30mMaximum time a connection can be idle
MPG_DATABASE_MAX_CONNECTINGintNo10Maximum concurrent connection attempts
MPG_DATABASE_CONNECT_TIMEOUTdurationNo10sConnection establishment timeout

Cache (Redis / Garnet)

VariableTypeRequiredDefaultDescription
MPG_GARNET_URLstringNoRedis-compatible cache URL (e.g., redis://localhost:6379). If unset, in-memory cache is used.

Logging

VariableTypeRequiredDefaultDescription
MPG_LOG_LEVELstringNoerrorLog level: debug, info, warn, error, fatal, panic
MPG_LOG_FORMATstringNojsonLog format: json (structured) or text

OpenTelemetry (Tracing)

VariableTypeRequiredDefaultDescription
MPG_OTEL_ENABLEDboolNofalseEnable OpenTelemetry tracing
MPG_OTEL_EXPORTER_OTLP_PROTOCOLstringNoOTLP protocol: grpc or http/protobuf
MPG_OTEL_EXPORTER_OTLP_ENDPOINTstringNoOTLP collector endpoint URL
MPG_OTEL_EXPORTER_OTLP_HEADERSstringNoOTLP authentication headers (comma-separated key=value)
MPG_OTEL_RESOURCE_ATTRIBUTESstringNoResource attributes (e.g., service.name=payment-gateway)
MPG_OTEL_EXPORTER_OTLP_INSECUREboolNofalseSkip TLS verification for OTLP endpoint

Rate Limiting

VariableTypeRequiredDefaultDescription
MPG_RATE_LIMIT_ENABLEDboolNotrueEnable request rate limiting
MPG_RATE_LIMIT_WINDOW_SIZEdurationNo5mSliding window size
MPG_RATE_LIMIT_MAX_REQUESTSintNo500Maximum requests per window
MPG_RATE_LIMIT_REQUESTS_PER_MINintNo100Maximum requests per minute
MPG_RATE_LIMIT_WHITELISTstringNo127.0.0.1,::1Comma-separated IPs to exempt from rate limiting

Encryption

VariableTypeRequiredDefaultDescription
MPG_SYSTEM_ENCRYPTION_KEYstringYesHex-encoded symmetric key for encrypting KMS credentials. Admin backend requires exactly 32 bytes (64 hex characters). Main backend accepts 32+ bytes, but use 32 bytes to keep environments consistent.
MPG_SYSTEM_SEARCH_HASH_KEYstringYesHex-encoded HMAC key for deterministic searchable encryption. Exactly 32 bytes (64 hex characters).

Licensing

VariableTypeRequiredDefaultDescription
MPG_LICENSING_BYPASSboolNofalseBypass license check. Only works if VERSION=dev. Never set in production.

Admin Backend Variables

Server

VariableTypeRequiredDefaultDescription
MPG_ADMIN_BACKEND_HOSTstringYesBind address (e.g., 0.0.0.0)
MPG_ADMIN_BACKEND_PORTintYesHTTP port (e.g., 8080)
MPG_ADMIN_BACKEND_HTTPSboolNofalseEnable TLS termination at the backend
MPG_ADMIN_BACKEND_HTTPS_CERTstringNoPath to TLS certificate file
MPG_ADMIN_BACKEND_HTTPS_KEYstringNoPath to TLS private key file
MPG_ADMIN_BACKEND_DOMAINstringNoPublic domain of the admin backend (optional; used for logging/metadata, not required by startup validation)
MPG_ADMIN_FRONTEND_DOMAINstringYesAdmin frontend domain for CORS allow-list (e.g., admin.yourcompany.com)
MPG_MAIN_BACKEND_DOMAINstringYesMain backend public domain
MPG_MAIN_FRONTEND_DOMAINstringYesMain frontend public domain
MPG_MAIN_FRONTEND_SERVICEstringYesInternal service hostname for the main frontend (admin backend uses this for internal reachability checks)
MPG_MAIN_FRONTEND_PORTstringYesInternal service port for the main frontend
MPG_MAIN_BACKEND_SERVICEstringYesInternal service hostname for the main backend (admin backend uses this for internal reachability checks)
MPG_MAIN_BACKEND_PORTstringYesInternal service port for the main backend

Authentication

VariableTypeRequiredDefaultDescription
MPG_SYSTEM_REFRESH_KEYstringYesSecret key for signing JWT refresh tokens (hex-encoded, exactly 64 bytes / 128 hex characters)
MPG_COOKIE_AUTH_KEYstringYesSession cookie authentication key (hex-encoded, 64 bytes recommended)
MPG_COOKIE_ENCRYPTION_KEYstringYesSession cookie encryption key (hex-encoded, 32 bytes)
MPG_WEBAUTHN_RPDISPLAYNAMEstringNoDisplay name shown in passkey dialogs (e.g., My Company Admin)
MPG_WEBAUTHN_DEBUGboolNofalseEnable verbose WebAuthn debug logging

External Services

VariableTypeRequiredDefaultDescription
MPG_MAIN_WORKER_SERVICE_URLstringNoInternal URL of the worker service for PDF proxy requests
MPG_LICENSING_AUTHORITY_URLstringNoLicensing Authority API base URL. Development commonly uses http://localhost:5173; staging/production should be HTTPS.

Main Backend Variables

Server

VariableTypeRequiredDefaultDescription
MPG_MAIN_BACKEND_HOSTstringYesBind address (e.g., 0.0.0.0)
MPG_MAIN_BACKEND_PORTintYesHTTP port (e.g., 8081)
MPG_MAIN_BACKEND_HTTPSboolNofalseEnable TLS at backend
MPG_MAIN_BACKEND_HTTPS_CERTstringNoTLS certificate path
MPG_MAIN_BACKEND_HTTPS_KEYstringNoTLS private key path
MPG_MAIN_BACKEND_DOMAINstringYesPublic domain for this backend
MPG_MAIN_FRONTEND_DOMAINstringYesMain frontend domain for CORS

Worker (PDF Generation)

VariableTypeRequiredDefaultDescription
MPG_MAIN_WORKER_GOTENBERG_URLstringNohttp://localhost:3000URL of the Gotenberg PDF service
MPG_MAIN_WORKER_TEMP_CACHE_DIRstringNoOS temp dir + /pdf-cacheLocal directory for temporary PDF caching (defaults to the host OS temp directory). In container deployments this is commonly set explicitly (e.g. /tmp/pdf-cache).
MPG_MAIN_WORKER_SERVICE_URLstringNoInternal URL where the worker HTTP server is reachable (used by the main API to proxy PDF requests)
MPG_MAIN_WORKER_HOSTstringNo0.0.0.0Worker HTTP server bind address
MPG_MAIN_WORKER_PORTintNo8090Worker HTTP server port
MPG_MAIN_WORKER_CONCURRENCYintNo10Maximum concurrent PDF jobs
MPG_MAIN_WORKER_SHUTDOWN_TIMEOUTintNo10Graceful shutdown timeout in seconds

Generating Secure Keys

Use openssl to generate cryptographically secure keys:

# 32-byte key (64 hex chars) — for SYSTEM_ENCRYPTION_KEY, SYSTEM_SEARCH_HASH_KEY, COOKIE_ENCRYPTION_KEY
openssl rand -hex 32

# 64-byte key (128 hex chars) — for COOKIE_AUTH_KEY, SYSTEM_REFRESH_KEY
openssl rand -hex 64

[!IMPORTANT] Generate unique keys for each environment (development, staging, production). Never reuse keys across environments. Rotate keys if they are ever exposed.

On this page