Common Fund Database
CFDB is a Python package for querying and serving enriched C2M2 (Crosscut Metadata Model) file metadata from Common Fund Data Coordinating Centers (DCCs) and Encode.
Quickstart
Installation
pip install git+https://github.com/abdenlab/cfdb.git
Requires Python 3.12 or later.
Matrix tile serving for Hi-C contact maps (see Matrix tile serving) is backed by the abdenlab/clodius fork, pinned to a commit sha of the public fork as an ordinary dependency — no separate install step is needed beyond the usual pip install / uv sync above.
Environment Variables
| Variable |
Description |
Default |
SYNC_API_KEY |
API key for the sync endpoint. If unset, sync is unprotected (suitable for local dev). |
- |
SYNC_DATA_DIR |
Root directory for downloaded sync data, the workflow cache ($SYNC_DATA_DIR/cache), and per-job workdirs ($SYNC_DATA_DIR/jobs). When unset the preprocessing/indexing workflow subsystem is disabled: /data falls through to direct upstream streaming, /index returns 503 for processable formats (BAM/VCF/etc.) and 404 for passthrough formats (CSV/TSV/bigWig). Both subdirectories must share a filesystem because LocalFsCache.put relies on os.replace atomicity. |
- |
WORKFLOW_WORKER_COUNT |
Local-dev only: number of workers the LAN pool (worker_lan) spawns. The API no longer leases a fixed count — its pool admits every discovered worker. In the ECS profile the concurrent worker fleet is bounded by ECS_MAX_WORKERS, with the AWS Fargate vCPU service quota as the hard ceiling. |
2 |
ECS_MAX_WORKERS |
ECS profile only: cap on concurrently-running ephemeral Fargate worker tasks. The provisioner counts the fleet before each RunTask and queues rather than spawning past this, so it bounds workers without limiting the queue (that is CFDB_WORKFLOW_MAX_ACTIVE). 0 disables the cap. |
16 |
WORKFLOW_POOL_NAMESPACE |
wool LAN discovery namespace shared by the API and the worker-pool process. Both processes MUST set the same value or dispatch will hang on NoWorkersAvailable. |
cfdb-workers |
CFDB_WORKER_TLS_CA |
Path to the shared CA certificate for the wool worker gRPC channel. When this and the cert/key below are all set, the API↔worker dispatch channel uses mutual TLS (mutual=True); when all three are unset the channel stays plaintext. Partial config fails fast at startup. The API and every worker MUST use certs signed by the same CA. See Worker mTLS. |
- |
CFDB_WORKER_TLS_CERT |
Path to this process's PEM certificate on the worker gRPC channel — the worker leaf cert on a worker (worker_main/worker_lan), the API client cert on the API. Must be signed by CFDB_WORKER_TLS_CA. |
- |
CFDB_WORKER_TLS_KEY |
Path to this process's PEM private key paired with CFDB_WORKER_TLS_CERT. |
- |
CFDB_WORKER_TLS_IDENTITY |
Logical name the API verifies worker certificates against, in place of the address it dialed. Workers answer on addresses assigned at launch — an awsvpc IP on Fargate, a bridge IP in local containers — that no certificate minted ahead of time can name, so without this the handshake cannot succeed. The worker leaf must carry this value as a SAN; certs/generate-worker-certs.sh mints the default. Set to the empty string to verify against the dialed address instead. Read by every process that dials: the API on the dispatch channel, and each worker on the graceful-stop channel wool opens back to its own subprocess — so the API and the workers MUST agree on this value, or drain fails its name check and in-flight work is lost with no TLS error anywhere. Ignored while mTLS is off. See Worker mTLS. |
cfdb-worker |
CFDB_TILESET_DISK_CACHE_BYTES |
Byte budget for the API task's local copies of contact-map artifacts. h5py opens a file rather than consuming a byte stream, so under the S3 profile an mcool must be pulled onto local disk before any tile can be read from it. Least-recently-used copies are evicted to stay inside the budget, and a copy currently being read is never removed. Keep this comfortably below the task's ephemeral storage, which it shares with SYNC_DATA_DIR and the container image — cloudformation/backend.yml sizes that disk with ApiEphemeralStorageGiB and passes this value with TilesetDiskCacheBytes, so the two move together. |
8589934592 (8 GiB) |
CFDB_TILESET_OPEN_MAX |
How many tilesets may be held open at once. Each is an open h5py handle over a potentially multi-GB file, so this is a file-descriptor bound rather than a memory one. A handle evicted while a request is still reading it is closed only once that reader finishes. |
8 |
CFDB_TILE_CACHE_BYTES |
Byte budget for the in-process tile cache. Bounded by bytes rather than entry count because a 256×256 float32 tile is roughly 350 KiB base64-encoded, so a plausible-sounding 20,000-entry cap would be several GB on a 2 GiB task. |
268435456 (256 MiB) |
CFDB_TILE_THREADS |
Threads used to run tile reads off the event loop. This bounds concurrency; it does not buy read parallelism — h5py serializes on a global lock unless linked against a thread-safe HDF5 build, which the published wheels are not, so matrix tile throughput is effectively serial per API process however high this is set. What it does buy is that a multi-second tile read cannot stall /data and /metadata. The real throughput levers are the tile cache and horizontal scaling. |
2 |
CFDB_TILESET_HYDRATE_TIMEOUT_S |
Seconds to wait for a cached artifact to be pulled onto local disk before answering 503 Retry-After. This cost lands on the first /tileset_info for a dataset, not on any tile. |
60 |
CFDB_TILESET_MAX_SOURCE_BYTES |
Refuse to materialize a contact map larger than this, checked before a byte is downloaded. 0 disables the guard. Set on the worker. The artifact for an .mcool is a copy of the upstream file, so an oversized — or mislabelled — source would otherwise fill the worker's disk and fail somewhere far less legible than at admission. |
21474836480 (20 GiB) |
CFDB_API_URL |
Base URL for the cfdb API |
http://localhost:8000 |
DATABASE_URL |
MongoDB connection string |
mongodb://127.0.0.1:27017 |
DATABASE_NAME |
Name of the MongoDB database to use |
cfdb |
MONGODB_TLS_ENABLED |
Enable X.509 certificate authentication (production) |
false |
MONGODB_CA_PATH |
Path to CA certificate bundle used when MONGODB_TLS_ENABLED=true |
/etc/cfdb/certs/global-bundle.pem |
MONGODB_RETRY_WRITES |
Enable retryable writes on the MongoDB client |
false |
Docker Startup
# 1. Start MongoDB (creates indexes, and restores a dump if one is present)
make mongodb
# 2. Start the API server
make api
# 3. Populate the database
curl -X POST http://localhost:8000/sync
This starts:
- MongoDB on port 27017 (with indexes)
- GraphQL/REST API on port 8000
The database starts empty. A 4DN sample dump used to be committed under database/, but it was removed and the directory gitignored, so a clean checkout has no data to restore and step 3 is how you get some — it is not optional. make mongodb still creates every index, so an empty database is a working one rather than a broken one.
database/ remains the drop-in point if you do have a dump: put a mongodump --gzip tree there (database/cfdb/*.bson.gz) and it is restored on the next make mongodb. It is mounted read-only at run time rather than baked into the image, so obtaining a dump later costs a container restart and not a rebuild.
Production (TLS/X.509)
# 1. Generate certificates (customize hostname/IP as needed)
./certs/generate-certs.sh mongodb.example.com 10.0.1.50
# Or use environment variables
MONGODB_HOSTNAME=mongodb.example.com MONGODB_IP=10.0.1.50 ./certs/generate-certs.sh
# 2. Set a strong sync API key - this will be used to trigger metadata synchronization
export SYNC_API_KEY=<your-secret-key>
# 3. Start MongoDB with TLS
make mongodb-prod
# 4. Start API with client certificate
make api-prod
The certificate script generates:
certs/ca/ca.pem - CA certificate (deploy to all containers)
certs/server/mongodb-server-bundle.pem - MongoDB server certificate
certs/clients/cfdb-api-bundle.pem - API client certificate
certs/clients/cfdb-materializer-bundle.pem - Materializer client certificate
Run ./certs/generate-certs.sh --help for full usage information.
Makefile Targets
| Target |
Description |
make mongodb |
Build and start MongoDB with sample data and indexes |
make api |
Build and start the API container |
make api-tiles |
Build and start the API container with matrix tile serving enabled, on a cache volume shared with the worker (local dev; see Serving tiles locally) |
make worker-tiles |
Start a containerized LAN worker pool on that same cache volume |
make materialize-files |
Manually materialize all file metadata (usually done via sync) |
make materialize-dcc DCC=hubmap |
Materialize a single DCC |
make schema |
Regenerate the checked-in schema.graphql from the Strawberry schema |
make certs |
Generate TLS certificates for production |
make mongodb-prod |
Start MongoDB with TLS/X.509 authentication |
make api-prod |
Start API with X.509 client certificate |
make worker-certs |
Generate the wool worker mutual-TLS material (CA + worker + API client certs) for local dev |
make worker-local-tls |
Start a local LAN worker pool with worker mTLS enabled |
Deploying the CloudFormation stacks
Each deployed environment runs on the same four CloudFormation stacks under cloudformation/, deployed under environment-specific stack names. Deploy them in dependency order (each imports exports from the earlier ones):
network.yml — VPC, subnets, security groups (including the worker SG), S3 gateway endpoint.
database.yml — DocumentDB cluster and connection-URL secret.
workers.yml — wool worker task definition, S3 artifact cache, worker IAM roles.
backend.yml — API service, ALB, and the IAM/env wiring that dispatches to the worker fleet.
Tear down in the reverse order (backend → workers → database → network); backend imports the worker exports, so it must be deleted first. Both the cfdb and cfdb-wool ECR repositories are prerequisites created out of band. Each MUST allow tag mutability (MUTABLE), because the moving-tag deploys re-push the :dev and :prod tags and an IMMUTABLE repository would reject the second push of either. If you want :<sha> tags to stay immutable while still allowing the moving tags to be re-pushed, configure ECR IMMUTABLE_WITH_EXCLUSION with wildcard filters exempting both dev and prod (so :<sha> is immutable and the moving tags are mutable). Give both repositories a lifecycle policy to prune untagged images.
Environments
Two environments share the account 605134458779 and region us-east-2. Every cross-stack export is ${AWS::StackName}-scoped, so the two sets of stacks coexist without collisions — but the physical names that AWS requires to be account- and region-unique (the ALB target group in particular) MUST be passed per environment, which is why TargetGroupName is a parameter.
|
dev |
prod |
| Stack names |
cfdb-network-dev, cfdb-db-dev, cfdb-workers-dev, cfdb-backend-dev |
cfdb-network-prod, cfdb-db-prod, cfdb-workers-prod, cfdb-backend-prod |
| Domain |
dev.cfdb.vis-api.link |
cfdb.visualizationhub.org |
| Hosted zone |
vis-api.link (Z09477406JQAR0KB7G87) |
visualizationhub.org (Z02332581YW11QLMXBXY4) |
| Moving tag |
:dev |
:prod |
| VPC CIDR |
10.2.0.0/21 |
10.3.0.0/21 |
| Ships when |
every merge to master, automatically |
a human dispatches Promote CFDB to prod and a reviewer approves |
Note the templates' parameter defaults (cfdb.vis-api.link, 10.2.0.0/21, cfdb-tg) match neither live environment — they exist only so a bare cloudformation deploy is not rejected for missing parameters. Always pass explicit overrides.
One parameter deliberately breaks that convention: workers.yml's BackendClusterName has no default, so a deploy that omits it is rejected outright. The convention rests on a wrong value failing visibly — a wrong DomainName is the wrong DNS, a wrong TargetGroupName