Skip to content

Aurora Database

This document describes how we use AWS Aurora Serverless v2 (PostgreSQL) for database operations in the Registration Backend service.

Overview

We use AWS Aurora Serverless v2 as our database. Aurora provides automatic scaling, high availability, and full PostgreSQL compatibility.

Database Setup

Aurora

Aurora is automatically provisioned by CDK. The application receives these environment variables:

  • Database connection details (host, port, database name)
  • Secret ARN pointing to credentials in AWS Secrets Manager

Infrastructure Configuration

CDK Setup

Aurora is set up in cdk.mts with environment-specific settings:

provisionAurora: true,
aurora: {
  minCapacity: 0.5,  // Minimum ACUs
  maxCapacity: 1,    // Maximum ACUs
}

The Aurora construct is defined in cdk/database/aurora.ts and handles:

  • Database cluster creation
  • Security group configuration
  • Secrets Manager integration
  • VPC configuration

Central backup strategy of Statista

  • KMS encryption key setup
  • Backup configuration

Capacity Units

Aurora uses Aurora Capacity Units for scaling (ACUs):

  • 1 ACU = 2 GB of memory + corresponding compute and networking
  • Minimum: 0.5 ACU
  • Maximum: 1 ACU
  • Scaling: Automatic in ~10 second increments based on load

Database Connection

Environment Variables

Aurora exports the following environment variables (defined in cdk/database/aurora.ts):

  • APP_DATABASE_HOST - Aurora cluster endpoint hostname
  • APP_DATABASE_PORT - Aurora cluster port (5432)
  • APP_DATABASE_NAME - Database name
  • APP_DATABASE_SECRET_ARN - ARN of the Secrets Manager secret

Connecting to the Database

We can use the database by calling getDb() from app/database/db.server.ts:

import { getDb } from "~/database/db.server.js";

const db = await getDb();

The getDb function automatically:

  • Builds the database connection using AWS
  • Retrieves credentials from Secrets Manager using the ARN which rotates every 30 days
  • Enables SSL for prod connections
  • Reuses connections across Lambda invocations

Backups

Aurora automatically creates:

  • Daily snapshots: Retained for 1 day (configurable)
  • Point-in-time recovery: Up to the retention period
  • Cross-region backups: Managed by our central backup account

The cluster is tagged with backup: enabled for AWS Backup integration.

Monitoring

We use Datadog to monitor Aurora performance and errors.