<@ULVA73B9P> could you tell me more about any pros...
# ask-marvin
i
@Marvin could you tell me more about any pros/cons of running a self hosted Prefect server (running on ECS)?
m
thought for 337.4 seconds
Great question. Assuming you’re on Prefect 3.x and planning to run the open-source server on AWS ECS, here’s a practical pros/cons rundown plus some ECS-specific guidance. Pros of self-hosting on ECS - Network and data control: Run everything inside your VPC (no egress to Prefect Cloud). Easy to keep the API private and put it behind an ALB/WAF. - Compliance/residency: You choose the region, storage (RDS), and retention policies. - Cost predictability at scale: If you already operate ECS/RDS/ElastiCache, infra costs can be straightforward (and sometimes lower at scale vs SaaS). - Operational flexibility: Pin/roll versions on your schedule, tune DB/Redis, set custom retention, and integrate with your own observability/alerting stack. - Auth at the edge: You can layer SSO or advanced auth via a reverse proxy in front of the server (while Prefect Server itself uses Basic Auth). Cons (compared to Prefect Cloud) - You run the platform: Provision/scale/patch API replicas, background services, RDS Postgres, Redis, ALB, backups, monitoring, and DR. - Cloud-only features are not available: No RBAC, SSO, audit logs, teams, service accounts, API keys, or object-level ACLs in OSS. Prefect Server supports Basic Auth only. - Upgrades are on you: Plan DB migrations, version pinning, rollbacks, and downtime windows. - External access friction: If developers and workers are outside the VPC, you must expose and secure the API correctly (TLS, Basic Auth, CORS/CSRF). - Observability/analytics: You’ll instrument logs/metrics/traces yourself; Prefect Cloud bundles more out of the box for orgs. What a production ECS setup typically looks like - Containers/services - One ECS service for API replicas behind an ALB:
Copy code
prefect server start --host 0.0.0.0 --no-services
- One ECS service (single task) for background services:
Copy code
prefect server services start
- One-off migration job during deploys:
Copy code
prefect server database upgrade -y
- Data plane - RDS Postgres (required for HA/multi-replica). Avoid SQLite in production. - Redis (ElastiCache) required for multi-server/event coordination and scaling. - Load balancer - ALB health check: /api/health on port 4200 - Configure keep-alive > ALB idle timeout (e.g., set
PREFECT_SERVER_API_KEEPALIVE_TIMEOUT=65
) - Security and settings - Basic Auth for server/API:
Copy code
# On the server
    PREFECT_SERVER_API_AUTH_STRING="username:password"

    # On all clients (workers, dev laptops) that call your API
    PREFECT_API_AUTH_STRING="username:password"
Store in AWS Secrets Manager and inject via ECS task definition. - CORS/CSRF for public endpoints:
Copy code
PREFECT_SERVER_API_CSRF_PROTECTION_ENABLED=true
    PREFECT_SERVER_API_CORS_ALLOWED_ORIGINS="<https://prefect.example.com>"
- UI config behind a proxy:
Copy code
PREFECT_UI_API_URL="<https://prefect.example.com/api>"
- Redis/messaging (for HA and scale) - Typical env you’ll see:
Copy code
PREFECT_MESSAGING_BROKER=prefect_redis.messaging
    PREFECT_MESSAGING_CACHE=prefect_redis.messaging
    PREFECT_SERVER_EVENTS_CAUSAL_ORDERING=prefect_redis.ordering
    PREFECT_SERVER_CONCURRENCY_LEASE_STORAGE=prefect_redis.lease_storage
    PREFECT_SERVER_DOCKET_URL="redis://<redis-host>:6379/1"
- Database tips - Connection URL example:
Copy code
PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://user:pass@rds-host:5432/prefect>"
- For large DBs, raise migration timeout:
Copy code
PREFECT_API_DATABASE_TIMEOUT=600
- Set event retention to control DB growth and vacuum routinely. When self-hosting on ECS is a great fit - You need strict VPC isolation or can’t use a public SaaS. - You already run ECS/RDS/ElastiCache and have central observability/ops. - You’re okay without Cloud-only features (RBAC, SSO, audit logs). - You want precise control over upgrades, backups, and sizing. When Prefect Cloud is usually easier
- You want org features (RBAC, SSO, audit logs, API keys, teams). - You want to offload upgrades, HA operations, and DB/Redis management. - You still keep workers in your VPC; only control-plane traffic goes to Cloud. - Optionally use PrivateLink and IP allowlists in Cloud for stricter egress control. Quick ECS checklist - Use the official image: prefecthq/prefect:3-latest - One API service (replicas) + one “services” service (1 task) - ALB with /api/health check - RDS Postgres + ElastiCache Redis - Secrets in AWS Secrets Manager for Basic Auth and DB creds - Enable CSRF and restrict CORS in production - Pin Prefect versions and plan DB migrations If you share a bit about your constraints (VPC-only vs public access, need for SSO/RBAC/audit, event volume/scale, who owns ops), I can recommend a concrete ECS architecture and provide a starter task definition/CloudFormation snippet tailored to your setup. References - Prefect docs: https://docs.prefect.io - Docker image: prefecthq/prefect