Setting Up a Production Deployment
This guide provides an overview for deploying HydroServer in a production environment. It is intended to help system administrators and developers get started with setting up key infrastructure needed to run HydroServer reliably and at scale based on their needs and use-cases. The guide includes an overview of required infrastructure and production configuration settings.
HydroServer Required Infrastructure
Each HydroServer release includes a container image that packages the core HydroServer website, APIs, and supporting services. This image follows the OCI (Open Container Initiative) standard and can be deployed on any platform that supports Docker or other OCI-compatible runtimes, including commercial cloud providers or local environments. The image comes pre-configured with Gunicorn as the web server for production use and can also be used to run administrative and deployment management commands.
HydroServer requires a PostgreSQL database (version 15 or higher) for data storage. At present, no specific PostgreSQL extensions are required, although you should ensure the database is accessible from the HydroServer deployment environment and configured with sufficient resources for your expected workload.
Because Gunicorn is not designed to serve static files on its own, HydroServer bundles WhiteNoise to serve static assets directly from Django whenever local static storage is used, with compression and appropriate cache headers applied automatically. Recommended approaches for serving static files will vary by platform, and details and examples are provided below.
For user account management, HydroServer requires access to an external email server to send account verification and password reset emails. Alternatively, you may integrate third-party identity providers (e.g. Google) for account creation and sign-in. When using third-party authentication exclusively, certain account management features—such as direct password resets via email—may not be required.
Preparing for Production Deployment
The example configurations provided in the deployment tutorials are intended for demonstration and evaluation purposes only. For production use, additional configuration and infrastructure are strongly recommended.
HydroServer Production Environment Variables
HydroServer’s Docker image supports the following environment variables for configuring a deployment:
SECRET_KEY
Secret used by Django to encrypt passwords and sign sessions. Must be securely generated and stored in production.
Example: See Django docsDEBUG
Enables debug mode. Must beFalsein production.
Example:True/FalseSTRICT_SECURITY
Enables CSRF protection, requires a realSECRET_KEY, applies default account rate limits, and requiresIDP_OIDC_PRIVATE_KEYwhen OIDC is enabled. Must beTruein production. The published Docker image already defaults toTrue; this only needs to be set explicitly for deployments that don't use that image.
Example:True/FalseIDP_OIDC_ENABLED
Whether HydroServer's built-in OIDC identity provider (discovery, authorize, token, and JWKS endpoints) is enabled. Defaults toTrue. WhenSTRICT_SECURITYis alsoTrue, one ofIDP_OIDC_PRIVATE_KEYorIDP_OIDC_PRIVATE_KEY_FILEmust be set, or startup will fail.
Example:True/FalseIDP_OIDC_PRIVATE_KEY
RSA private key (PEM format) used to sign OIDC tokens issued by HydroServer's identity provider. Generate one with:bashopenssl genpkey -algorithm RSA -out oidc_private_key.pem -pkeyopt rsa_keygen_bits:2048Set this to the contents of that file, or use
IDP_OIDC_PRIVATE_KEY_FILEinstead to point at its path. Keep it secret and stable across restarts — rotating it invalidates any tokens signed with the old key.
Example: contents ofoidc_private_key.pemIDP_OIDC_PRIVATE_KEY_FILE
Path to a PEM file containing the RSA private key described above, as an alternative to settingIDP_OIDC_PRIVATE_KEYdirectly. Takes precedence overIDP_OIDC_PRIVATE_KEYif both are set.
Example:/run/secrets/oidc_private_key.pemPROXY_BASE_URL
Base URL for your HydroServer instance.
Example:https://hydroserver.your-domain.comDATABASE_URL
PostgreSQL connection string.
Example:postgresql://hsdbadmin:securepassword123@127.0.0.1:5432/hydroserverCACHE_URL
Connection string for Django's cache backend. If unset andSTRICT_SECURITYisTrue(as in production), HydroServer defaults to a database-backed cache table inDATABASE_URLshared across worker processes and replicas. If unset andSTRICT_SECURITYisFalse, it uses a per-process in-memory cache. Set this to use a dedicated cache service instead, such as Redis.
Example:redis://127.0.0.1:6379/1ACCOUNT_SIGNUP_ENABLED
Whether public account creation is allowed, by email or through a third-party provider.
Example:True/FalseACCOUNT_OWNERSHIP_ENABLED
Whether new accounts can create or own workspaces by default. Admins can override per user.
Example:True/FalseSOCIALACCOUNT_SIGNUP_ONLY
IfTrue, new accounts can only be created through configured third-party providers. Example:True/FalseSMTP_URL
Connection string for sending emails.
Example:smtp://127.0.0.1:1025DEFAULT_FROM_EMAIL
Email address used for account management emails if SMTP is configured.
Example:noreply@example.comMEDIA_STORAGE_ENABLED
Whether HydroServer will accept file uploads for site/datastream linked resources, and expose them at/media/. Defaults toFalse— instances that don't want to manage file storage can leave this off and only use external URL linked resources, without needing to configureMEDIA_STORAGE_BACKENDbelow at all. This does not affect external URL-linked resources, which are always allowed.
Example:TrueMEDIA_STORAGE_BACKEND
Dotted path to the Django storage backend used to store hosted linked resources (only relevant whenMEDIA_STORAGE_ENABLEDisTrue). Defaults todjango.core.files.storage.FileSystemStorage(local disk), which is not recommended for production — set this explicitly tostorages.backends.s3.S3Storageorstorages.backends.gcloud.GoogleCloudStorage.
Example:storages.backends.s3.S3StorageMEDIA_STORAGE_OPTIONS
JSON object of keyword arguments passed toMEDIA_STORAGE_BACKEND.
Example (S3):{"bucket_name": "hydroserver-media-your-account-id", "location": "media"}
Example (GCS):{"bucket_name": "hydroserver-media-your-project-id", "project_id": "your-gcp-project-id", "location": "media"}STATIC_STORAGE_BACKEND
Dotted path to the Django storage backend used to serve static files. Defaults todjango.contrib.staticfiles.storage.StaticFilesStorage(local disk), which is not recommended for production — set this explicitly tostorages.backends.s3.S3Storageorstorages.backends.gcloud.GoogleCloudStorage.
Example:storages.backends.s3.S3StorageSTATIC_STORAGE_OPTIONS
JSON object of keyword arguments passed toSTATIC_STORAGE_BACKEND.
Example (S3):{"bucket_name": "hydroserver-static-your-account-id", "location": "static"}
Example (GCS):{"bucket_name": "hydroserver-static-your-project-id", "project_id": "your-gcp-project-id", "location": "static"}STATIC_HOST
Optional origin prefixed toSTATIC_URLto front static files served by HydroServer with a CDN (e.g., Amazon CloudFront). Only applied whenSTATIC_STORAGE_BACKENDis local. Leave unset to serve static files at a relative/static/path.
Example:https://d123abc4567.cloudfront.netWHITENOISE_MAX_AGE
Cache-Controlmax-age, in seconds, that WhiteNoise sets on locally served static files. Defaults to86400(1 day).
Example:86400WHITENOISE_USE_FINDERS / WHITENOISE_AUTOREFRESH
Development conveniences that let WhiteNoise serve static files without runningcollectstaticand pick up changes without a restart. Both default to the value ofDEBUGand should beFalsein production.
Example:False
Hosts, Origins, and Cookies
ALLOWED_HOSTS
Additional host names this instance responds to, as a comma-separated list. The host inPROXY_BASE_URLis always allowed, so set this only if HydroServer is also reached through other host names.
Example:hydroserver.your-domain.com,www.hydroserver.your-domain.comCSRF_TRUSTED_ORIGINS
Comma-separated list of origins trusted to make unsafe (e.g.POST) requests with a session cookie. Defaults toPROXY_BASE_URL. Add the origin of any separately hosted frontend that uses session authentication.
Example:https://hydroserver.your-domain.com,https://app.your-domain.comSAME_ORIGIN_FRONTEND
Whether the Data Management App is served from the same origin as HydroServer, as it is in the published Docker image. WhenTrue,WEB_CLIENT_URLdefaults toPROXY_BASE_URL. Defaults toFalse.
Example:TrueWEB_CLIENT_URL
The URL of the Data Management App, where users are sent after signing in or out of HydroServer's account pages. Defaults toPROXY_BASE_URLwhenSAME_ORIGIN_FRONTENDisTrue, otherwise to the local development frontend.
Example:https://hydroserver.your-domain.comACCOUNT_RETURN_URL_ALLOWED_HOSTS
Comma-separated list of additional hosts (with ports, if needed) that the account pages may send users back to after signing in, signing up, or signing out. Set this for separately hosted apps that link users to HydroServer's account pages.
Example:app.your-domain.comCORS_ALLOW_CREDENTIALS
Whether browsers may send cookies with cross-origin requests to HydroServer's APIs. Defaults toFalsewhenSTRICT_SECURITYisTrue. Cross-origin apps should normally authenticate with OIDC access tokens instead.
Example:FalseSESSION_COOKIE_NAME / CSRF_COOKIE_NAME
Names of the session and CSRF cookies. Default tohs_sessionandcsrftoken. Change them only if they conflict with another application on the same domain.
Example:hs_sessionSESSION_COOKIE_AGE
How long, in seconds, a sign-in session lasts. Defaults to86400(1 day).
Example:86400NOINDEX
IfTrue, adds anX-Robots-Tag: noindexheader to every response so search engines don't index the instance. Useful for staging and demo instances. Defaults toFalse.
Example:True
Database Connections
SSL_REQUIRED
IfTrue, requires SSL for the database connection (sslmode=require). Defaults toFalse.
Example:TrueDB_POOL_MIN_SIZE / DB_POOL_MAX_SIZE / DB_POOL_TIMEOUT
Size of each HydroServer process's database connection pool, and how many seconds a request waits for a free connection. Default to5,10, and60. Make sure the total across all processes and replicas stays below your database's connection limit.
Example:5/10/60CONN_MAX_AGE / CONN_HEALTH_CHECKS
Django's persistent connection lifetime in seconds and whether to check connections before reuse. Default to0andTrue.
Example:0/True
Rate Limiting
API_RATE_LIMITS
JSON object setting request rate limits for the Data Management API, withanonymousandauthenticatedrates. Leave unset to disable API rate limiting.
Example:{"anonymous": "20/s", "authenticated": "50/s"}ACCOUNT_RATE_LIMITS
JSON object of django-allauth rate limits for account actions such as sign-in, sign-up, and password reset. WhenSTRICT_SECURITYisTrue, allauth's default limits apply unless you override them here.
Example:{"login_failed": "10/m/ip,5/5m/key"}
OIDC Tokens and Service Accounts
IDP_OIDC_ACCESS_TOKEN_EXPIRES_IN
Lifetime, in seconds, of access tokens issued by HydroServer's OIDC identity provider. Defaults to3600(1 hour).
Example:3600IDP_OIDC_ROTATE_REFRESH_TOKEN
Whether a new refresh token is issued each time a refresh token is used. Defaults toTrue.
Example:TrueSERVICE_ACCOUNT_EMAIL_DOMAIN
Domain used for the generated email address that identifies each service account. Defaults tohydroserver.local.
Example:hydroserver.your-domain.com
Task Runs and Logging
TASK_RUN_RETENTION_DAYS
Number of days of Job Orchestration System task run history to keep. Older runs are deleted by a scheduled cleanup task, which requires a Celery worker and scheduler and keeps running whenCELERY_ENABLEDisFalse. Defaults to7.
Example:30TASK_RUN_CLEANUP_CRONTAB
Crontab schedule (minute, hour, day of month, month, day of week) for the task run cleanup. Defaults to0 3 * * *(daily at 03:00).
Example:0 3 * * *LOG_FORMAT
standardfor plain-text logs orjsonfor structured JSON logs. Defaults tostandard.
Example:json
Storing Secrets
Store sensitive environment variables (database credentials, API keys, etc.) securely, using a secret manager such as AWS Systems Manager Parameter Store, HashiCorp Vault, or GCP Secret Manager. Avoid committing secrets to version control or hardcoding them into configuration files.
Serving Static and Media Files
Static files (CSS, JavaScript, and images bundled with the application) are served directly by HydroServer, using Django WhiteNoise, whenever STATIC_STORAGE_BACKEND is local. WhiteNoise applies gzip compression and necessary cache headers automatically. For higher-traffic deployments, set STATIC_HOST to a CDN domain (e.g., AWS CloudFront) pointed at your HydroServer instance as its origin; WhiteNoise's cache headers let the CDN serve cached static assets without re-fetching from HydroServer on every request.
Media files are only relevant if MEDIA_STORAGE_ENABLED is True — instances that only use external URL linked resources for their sites/datastreams can leave media storage unconfigured. Django is not optimized for storing or serving user-uploaded media files in production. Recommended approaches include:
- Using a reverse proxy (e.g., NGINX) to serve the media volume.
- Offloading storage and delivery to a cloud service such as Amazon S3 or Google Cloud Storage, optionally integrated with a Content Delivery Network (CDN) service such as AWS CloudFront or Google Cloud CDN for improved performance.
Since these approaches bypass HydroServer’s internal authorization system, you may need to add additional security controls to protect private media files (for example, by using signed URLs).
Sign-In Provider Icons
OpenID Connect sign-in buttons show the icon at provider-icons/<provider ID>.png in static storage, or text only if there's no file. Icons for github, google, microsoft, and orcid are included.
To add or replace an icon, publish a small square PNG (about 64 × 64 pixels) to that path during deployment:
| Static storage | Where to put icons |
|---|---|
| Cloud bucket (S3, Google Cloud Storage) | provider-icons/ under the static location (e.g. static/provider-icons/utahid.png) |
| Local, published image | A directory mounted at /app/django/staticfiles/provider-icons; restart after changes |
| Local, custom image or development | django/static/provider-icons/ |
To use another path or format, set "icon" in the provider's Settings, e.g. "icon": "provider-icons/cuahsi.svg".
New icons can take up to five minutes to appear. collectstatic --clear deletes icons published to a bucket, and manifest (content-hashed) static storage isn't supported.
Email Configuration
HydroServer requires an SMTP server to send emails (e.g., password resets, email verification). For production, use a reliable external email provider such as Amazon Simple Email Service (SES) or Gmail SMTP with authentication and TLS enabled.
HTTPS
HydroServer should be served exclusively over HTTPS in production. Options include:
- Terminating TLS at a reverse proxy such as NGINX
- Using a managed certificate service (e.g., AWS Certificate Manager (ACM), GCP Certificate Manager, Let’s Encrypt)
Load Balancing and System Requirements
When planning a production deployment of HydroServer, it is important to consider performance, scalability, and fault tolerance. Key areas include:
Web Server Load Balancing
For deployments that need to serve a large number of concurrent requests, place HydroServer behind a load balancer (such as AWS Application Load Balancer (ALB), Google Cloud Load Balancer, or NGINX). The load balancer distributes incoming traffic across multiple HydroServer containers or instances, improving reliability and response times. When running HydroServer on serverless architecture, scaling HydroServer up and down based on user traffic can also help lower costs.Application Server Requirements
HydroServer runs on the Django Framework, which by default uses a single-threaded development server. In production, you should run HydroServer behind the built-in Gunicorn service with worker processes scaled to the available CPU and memory resources. Containers or VMs should be sized to handle the expected workload, and additional replicas can be added horizontally. Web server resource requirements will vary greatly depending on expected concurrent traffic and types of workloads being performed with your HydroServer deployment.Database Requirements
PostgreSQL should be provisioned with sufficient CPU, memory, and disk throughput to handle both transactional workload and background tasks (e.g., data ingestion). It is recommended to run PostgreSQL as a managed service where available, or to configure regular backups and monitoring if self-managed.Database Connection Pooling
When scaling up the number of HydroServer web servers or worker processes, a large number of short-lived database connections can be generated under high traffic loads. To avoid overwhelming PostgreSQL with connection overhead for larger deployments, consider setting up a connection pooling service such as PgBouncer. Connection pooling reduces latency, stabilizes performance under high concurrency, and allows more efficient use of database resources.
Security and Access Control
When deploying HydroServer in production, you should implement multiple layers of security to reduce risk:
Database Access
Restrict external access to the PostgreSQL database. It should only be accessible by the HydroServer service or other explicitly authorized services (e.g., a database backup service). Consider using managed database services that provide built-in encryption, automated backups, and fine-grained access control.Network Restrictions
Configure a firewall or security group to only allow required inbound traffic (typically HTTPS for HydroServer). Deny all other external connections by default, and restrict outbound access to only the services HydroServer needs to reach.Secure Communication
Ensure all internal services (e.g., HydroServer, reverse proxy, database) communicate over a secure network. For distributed deployments, use TLS for connections between services where possible.Authentication and Authorization
Apply the principle of least privilege for all user roles and service accounts. For external APIs, consider rate limiting and monitoring to detect unusual activity.Regular Updates
Keep HydroServer, its dependencies, and all supporting infrastructure (e.g., Docker base images, PostgreSQL) up to date with the latest security patches.Monitoring and Logging
Enable logging at both the application and infrastructure layers. Use monitoring tools to detect suspicious activity, unauthorized access attempts, and to track overall system health. HydroServer also provides a/health-checkendpoint that can be used by external monitoring services.
Enabling Celery for HydroServer
HydroServer's Job Orchestration System uses Celery to run data ingestion, data product, and quality monitoring tasks in the background. To use it, you must set up several additional services, including at least one worker instance, a scheduler, and a broker such as Redis. The rest of HydroServer works without these services.
The following HydroServer settings can be used to configure Celery:
CELERY_ENABLED
Controls whether the Job Orchestration System is enabled. Defaults toTrue. Set it toFalseif you don't run the Celery services, or to turn off orchestration on an instance that does. WhenFalse:- Users can't create new tasks or run existing tasks. The API returns
501 Not Implementedfor these requests, and the Job Orchestration page in the Data Management App disables these buttons. - Users can still view, edit, and delete existing tasks, and can create, edit, and delete data connections.
- The scheduler stops sending scheduled tasks, and workers skip any tasks they receive, including ones that were queued before the setting changed. Data connection notification emails are not sent. The task run cleanup (see
TASK_RUN_RETENTION_DAYS) keeps running if able. - Task schedules are left unchanged, so they resume as they were when you set
CELERY_ENABLEDback toTrue.
Set
CELERY_ENABLEDto the same value on the web server, worker, and scheduler containers, and restart all of them after changing it.
Example:True/False- Users can't create new tasks or run existing tasks. The API returns
CELERY_BROKER_URL The URL of the broker service Celery should use to orchestrate tasks. Example:
redis://127.0.0.1:6379/0
To start a Celery worker, use the following entrypoint command with HydroServer’s Docker image. This container must have database and broker access.
celery -A hydroserver worker --loglevel=INFOTo start a Celery scheduler, use the following entrypoint command with HydroServer’s Docker image. This container must have database and broker access.
celery -A hydroserver beat --loglevel=INFOHydroServer Management Commands
After provisioning your infrastructure, but before starting HydroServer’s web server, you must run several management commands to complete setup. In the demo deployments from the deployment tutorials, these steps are bundled into the convenience command:
python manage.py run_demoThis command is intended for demonstration purposes only. It runs the required setup steps and starts Django’s development server. Do not use it in production. For production deployments, run the following commands individually, or configure an automated process to run them once your database and storage volumes are ready:
python manage.py migrateInitializes all required HydroServer database tables in your PostgreSQL database.
This must be run first. You may also need to rerun it when upgrading HydroServer (always check new version release notes first for details).
python manage.py collectstaticCopies HydroServer’s static files to the deployment location.
Run this after upgrades to ensure new or updated static files are available.
python manage.py createsuperuserCreates the initial admin account for your HydroServer instance (Django will prompt for an email and password).
Run once only. Additional admin accounts can be created later through the dashboard.
Starting HydroServer with Gunicorn
HydroServer’s Docker image comes pre-installed with Gunicorn as the production-ready application server. After provisioning all deployment infrastructure, completing database migrations, collecting static files, and setting up an admin user, you can start the web server using Gunicorn.
Use the following entrypoint command when starting a HydroServer container in production:
gunicorn hydroserver.wsgi:application --bind 0.0.0.0:8000 --workers 3hydroserver.wsgi:application
Points Gunicorn to HydroServer's WSGI application.--bind 0.0.0.0:8000 Exposes the application on all container network interfaces at port 8000. This will work for most deployment methods, but it can be adjusted if needed.
--workers 3 The number of worker processes Gunicorn will spawn. Adjust this number based on available CPU cores and expected traffic. Gunicorn generally recommends setting the number of workers to (2 * num_cores) + 1. The example above is intended for a HydroServer instance running on a single core.
After the server is running, visit your configured domain in a browser to access HydroServer.
Updating to a New Version
To update an existing HydroServer deployment to a new version:
Read the release notes for every version between your current version and the target version. Some releases include required manual steps, database migration prerequisites, or breaking changes that must be addressed before or after upgrading. Release notes are published on the HydroServer GitHub releases page.
Back up your database. Always take a snapshot of your PostgreSQL database before applying an upgrade, especially for releases that include database migrations.
Pull the new image. Update your deployment configuration to reference the new container image version and redeploy.
Run post-deployment management commands. After the new container is running, execute the following:
bashpython manage.py collectstaticCollects any new or updated static files included in the release.
bashpython manage.py migrateApplies any database schema changes included in the release.
Restart Celery workers (if applicable). If your deployment uses Celery for background task scheduling, restart your worker and beat containers after the upgrade to pick up any changes.
