Skip to content
InfraChallenge Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Architecture

How the patent reviewer runs on AWS, and why each part is there.

The app runs in eu-west-2 (London), the region nearest the team. CloudFront with WAF serves the static client from S3. It also passes /api/* and /ws through a VPC origin to an internal ALB, which sits in front of Fargate tasks in three Availability Zones. Aurora PostgreSQL Serverless v2 sits in isolated data subnets, ready for the move off SQLite (see Blocker 1).

Each environment (dev, staging, prod) has its own AWS account. A one-time bootstrap stack in each account creates the Terraform state bucket and the GitHub OIDC roles.

Request flow

The layers

Why this design

Each row is a design target, the choice that answers it, and where that choice lives in infrastructure/.

Design load: 1,000 to 10,000 concurrent users

Fargate behind an internal ALB. Prod runs 3 to 12 tasks, with target tracking on CPU (60%) and on ALB requests per target. Aurora Serverless v2 runs between 0.5 and 4 ACU. These are starting values, not measurements; see Capacity.

modules/service/ecs.tf, modules/service/autoscaling.tf, modules/data/main.tf, envs/prod/terraform.tfvars

Target: 99.9% availability

The stack spans three AZs, and prod has one NAT gateway in each. Tasks spread across the private subnets with AZ rebalancing, and the Aurora writer and reader run in different AZs. Rolling deploys keep 100% of capacity. The circuit breaker and the 5xx alarm roll back a bad deploy. The ALB health-checks /healthz. Blocker 1 still applies.

modules/network/main.tf, modules/service/ecs.tf, modules/service/alarms.tf, modules/data/main.tf

Low latency in the US, Europe and Asia

CloudFront (PriceClass_All) serves the static client from edge locations. API and WebSocket traffic enters at the nearest edge and travels to the London ALB through a VPC origin. The application itself runs in one region. eu-west-2 is the primary region because it is the region nearest the team.

modules/edge/main.tf, envs/*/terraform.tfvars

SOC 2 technical controls

SOC 2 audits the organisation’s controls, so this makes no compliance claim. The Terraform supplies these technical controls:

Criterion Control in the code
CC6.1 Customer-managed KMS keys with rotation for every data store. Least-privilege roles: the task role can only write telemetry (log streams in the metrics log group, X-Ray segments in this region), and the execution role can read only two secrets. Private subnets.
CC6.6 WAF managed rules and a rate limit. An internal ALB reachable only through the CloudFront VPC origin. No public IPs except NAT.
CC6.7 TLS 1.2+ at CloudFront and the ALB, rds.force_ssl, and TLS-only bucket policies.
CC6.8 ECR scan on push, and immutable tags.
CC7.2 CloudWatch alarms to SNS, including a burn-rate alarm on AI suggestion failures that also rolls back a release. Application audit events for document reads and saves. VPC flow logs. See Observability.
CC8.1 Everything in code. Apply and deploy run only from a protected GitHub Environment, and plans run on pull requests.
A1.2 Aurora backups (35 days in prod), deletion protection, multi-AZ instances, and versioned state and site buckets.

What is not built is listed under Known gaps.

Several deploys a day

GitHub OIDC, so there are no long-lived keys. The deploy role is scoped to fixed resource names. App deploys register a new task definition revision without running Terraform. Immutable ECR tags make a rollback exact.

bootstrap/iam.tf, modules/service/ecs.tf, modules/service/ecr.tf

Little to operate

Managed services only: Fargate (no hosts), Aurora Serverless v2, ALB, CloudFront, AWS managed WAF rule groups, and an RDS-managed master password. Five plain modules, the same main.tf in every environment, and S3-native state locking with no DynamoDB table.

modules/*, envs/*/main.tf, envs/*/backend.tf

A protected OpenAI key

The key lives in a Secrets Manager secret encrypted with a customer-managed key. Terraform creates the secret empty; the value is set out of band, and ECS injects it when a task starts. Only the execution role can read it. Each environment has its own key, in its own account. Egress to OpenAI leaves through the fixed IPs of the NAT gateways (nat_public_ips).

modules/data/main.tf, modules/service/iam.tf, modules/service/ecs.tf, modules/network/main.tf

Protected document data

Aurora sits in data subnets with no route to the internet, and its security group admits only the task security group. Storage, Performance Insights, logs and secrets are encrypted with customer-managed keys. The database requires TLS and has IAM database authentication enabled. When deletion protection is on, a final snapshot is taken.

modules/data/main.tf, modules/network/main.tf, modules/service/security_groups.tf

Deploy strategy

Growing to more regions

When US customers need it, the next step is a separate stack in us-east-1: a copy of an envs/ directory with a new region and domain, and its own data. Asia gets a stack only when a customer, or the latency data, asks for one.

Was this page helpful?