{"id":"6b09a4b4ff996234422a2692","slug":"aws-scalable-web-architecture","title":"A scalable web portal on AWS – from one server to millions of users (CloudFront, ALB, ECS Fargate, Aurora, ElastiCache, SQS, CDK)","summary":"We take the pierogi shop's portal through five stages of growth – from a single machine to an architecture for millions of users. CloudFront and S3 for static files, a stateless API on ECS Fargate behind an Application Load Balancer in three Availability Zones, Aurora with read replicas, ElastiCache (Valkey) as a cache, SQS for background work, autoscaling policies and costs. Everything as AWS CDK in TypeScript.","servedLang":"en","availableLangs":["pl","en"],"topics":["aws-scalability","aws-s3","aws-sqs"],"techs":["typescript","node"],"tags":["aws","scalability","cloudfront","alb","ecs-fargate","aurora","elasticache","valkey","autoscaling","multi-az","aws-cdk","well-architected"],"level":"advanced","kind":"tutorial","access":"public","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":24,"stats":{"views":1,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T15:41:40.513Z","updatedAt":"2026-11-27T17:32:23.379Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"amber","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"Scalable web application architecture on AWS step by step – CloudFront with a VPC origin, S3 with OAC, ALB, ECS Fargate with autoscaling, Aurora Serverless v2 with replicas, ElastiCache Serverless Valkey (cache-aside), SQS and Fargate Spot, multi-AZ, costs and Well-Architected; AWS CDK code (TypeScr","wordCount":4621,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Halina's pierogi shop appeared on a TV cooking show. The next day the portal with the menu and online orders, which had run happily on a single machine for two years, got as much traffic in an hour as it used to get in a month – and went down. In this tutorial we walk the road it should have walked earlier: from one server to an architecture that serves millions of users. At every stage we change only what is actually the bottleneck."}]},{"type":"callout","attrs":{"variant":"info","title":"In a nutshell"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Statelessness first, scale second.","marks":[{"type":"bold"}]},{"type":"text","text":" An application that keeps no sessions or files on local disk can run as 3 or 40 copies behind a load balancer – the rest is autoscaling configuration."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The cheapest request is the one that never reaches the database.","marks":[{"type":"bold"}]},{"type":"text","text":" CloudFront at the edge, a cache in ElastiCache and read replicas take most of the work off the writer database."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Slow things go to a queue.","marks":[{"type":"bold"}]},{"type":"text","text":" SQS separates the user's response from background work, and workers scale with queue depth – down to zero, too."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"What you will build"},"content":[{"type":"paragraph","content":[{"type":"text","text":"An AWS CDK stack (TypeScript) for the portal: a VPC across three Availability Zones (AZs), a private S3 bucket with the SPA behind CloudFront (Origin Access Control), an internal Application Load Balancer reachable only through a CloudFront VPC origin, an API on ECS Fargate (ARM/Graviton) autoscaling on CPU and request count, Aurora PostgreSQL Serverless v2 with a replica, ElastiCache Serverless (Valkey), an SQS queue with a DLQ and workers on Fargate Spot. Plus the Node.js API code: read/write splitting, cache-aside with stampede protection, health checks and graceful shutdown. Download the code (11 files) as a ZIP."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Prerequisites:","marks":[{"type":"bold"}]},{"type":"text","text":" an AWS account with AWS CLI v2 ("},{"type":"text","text":"aws configure sso","marks":[{"type":"code"}]},{"type":"text","text":"), Node.js 22+, Docker (to build images), container and SQL basics. The "},{"type":"text","text":"S3","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-s3"}}]},{"type":"text","text":" and "},{"type":"text","text":"SQS","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-sqs"}}]},{"type":"text","text":" tutorials help – I don't repeat them here."}]},{"type":"stats","attrs":{"items":[{"value":"6","label":"Well-Architected pillars","hint":"since 2021, including sustainability"},{"value":"15","label":"read replicas in an Aurora cluster","hint":"one reader endpoint"},{"value":"6 copies","label":"of Aurora data","hint":"across three Availability Zones"},{"value":"0.5 ACU","label":"minimum per instance in this stack","hint":"Serverless v2 can even go down to 0"}]}},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  U([Users]) --> CF[CloudFront<br/>edge cache + WAF]\n  CF -->|OAC| S3[(S3: SPA)]\n  CF -->|VPC origin| ALB[Internal ALB]\n  subgraph VPC[VPC – 3 Availability Zones]\n    ALB --> API[API on ECS Fargate<br/>3–40 tasks]\n    API --> C[(ElastiCache<br/>Valkey)]\n    API -->|writes| W[(Aurora writer)]\n    API -->|reads| R[(Aurora reader)]\n    W -.replication.-> R\n    API -->|jobs| Q[[SQS + DLQ]]\n    Q --> WK[Fargate Spot workers<br/>0–20 tasks]\n    WK --> W\n  end","caption":"Target architecture (stage 4) – who talks to whom"}},{"type":"heading","attrs":{"level":2,"id":"the-rule-scale-what-hurts"},"content":[{"type":"text","text":"The rule: scale what hurts"}]},{"type":"paragraph","content":[{"type":"text","text":"The most common mistake when designing \"for millions\" is building stage 4 straight away for a product with a hundred users: you pay for NAT gateways, clusters and replicas, and the team maintains infrastructure instead of shipping features. The opposite mistake – no plan at all – ends the way it did for Halina. The sensible path is an architecture you can grow without rewriting the application, plus metrics that tell you when to move on."}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Stage"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Scale (roughly)"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Bottleneck"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What changes"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"0"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"up to ~1k users"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nothing – simplicity wins"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"one machine: app + database"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"1"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"~10k"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"database and app fight for RAM, static files load the server"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"managed database (RDS Multi-AZ), S3 + CloudFront"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"2"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"~100k"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"one app server = no redundancy"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"stateless API, ALB, ECS Fargate in 3 AZs, autoscaling"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"3"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"~1M"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the writer database (reads!)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"edge cache, ElastiCache, read replicas"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"4"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"10M+"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"synchronous, slow operations"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SQS and workers, RDS Proxy, later data partitioning"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"User counts are indicative – what matters is the traffic profile (requests per second at peak, the share of reads) and what the metrics say. I cover metrics and costs separately in the "},{"type":"text","text":"observability tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-observability-and-cost"}}]},{"type":"text","text":"."}]},{"type":"heading","attrs":{"level":2,"id":"stage-0-one-server"},"content":[{"type":"text","text":"Stage 0. One server"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  U([Users]) --> EC2[EC2 / Lightsail<br/>Node.js + PostgreSQL + files]","caption":"Stage 0: everything on one machine"}},{"type":"paragraph","content":[{"type":"text","text":"To start with, a single EC2 (or Lightsail) instance with the app, the database and the files is fine – it costs a dozen or so dollars a month and is easy to understand. But even here it pays to follow three rules that make every later step easier: configuration from environment variables, not from files on the server ("},{"type":"text","text":"Twelve-Factor App","marks":[{"type":"link","attrs":{"href":"https://12factor.net/"}}]},{"type":"text","text":"); automatic database backups stored off the machine; infrastructure described as code (CDK, Terraform), not clicked together."}]},{"type":"heading","attrs":{"level":2,"id":"stage-1-a-separate-database-and-static-files-at-the-edge"},"content":[{"type":"text","text":"Stage 1. A separate database and static files at the edge"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  U([Users]) --> CF[CloudFront]\n  CF --> S3[(S3: JS, CSS, photos)]\n  U --> EC2[EC2: API]\n  EC2 --> RDS[(RDS PostgreSQL<br/>Multi-AZ)]","caption":"Stage 1: managed database and a CDN"}},{"type":"paragraph","content":[{"type":"text","text":"The first two changes give the most for the least. "},{"type":"text","text":"The database moves to Amazon RDS","marks":[{"type":"bold"}]},{"type":"text","text":" in Multi-AZ mode – AWS handles backups, patching and automatic failover to a standby instance in another Availability Zone when the primary fails. "},{"type":"text","text":"Static files (the built frontend, dish photos) go to S3 behind CloudFront","marks":[{"type":"bold"}]},{"type":"text","text":" – the API server stops wasting threads on serving JavaScript, and users get files from the nearest point of presence (PoP). How to configure the bucket securely is covered in "},{"type":"text","text":"S3 bucket security","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-s3-bucket-security"}}]},{"type":"text","text":"."}]},{"type":"heading","attrs":{"level":2,"id":"stage-2-a-stateless-api-behind-a-load-balancer-in-three-zones"},"content":[{"type":"text","text":"Stage 2. A stateless API behind a load balancer in three zones"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  U([Users]) --> CF[CloudFront]\n  CF --> ALB[Application Load Balancer]\n  ALB --> A1[API – AZ a]\n  ALB --> A2[API – AZ b]\n  ALB --> A3[API – AZ c]\n  A1 & A2 & A3 --> RDS[(RDS Multi-AZ)]","caption":"Stage 2: many API copies in three Availability Zones"}},{"type":"paragraph","content":[{"type":"text","text":"A single application machine is a single point of failure and a performance ceiling. To run many copies, the application has to be "},{"type":"text","text":"stateless","marks":[{"type":"bold"}]},{"type":"text","text":": sessions in tokens or in ElastiCache (not in process memory), files in S3 (not on disk), scheduled jobs in EventBridge Scheduler or a single worker (not in every copy). Then an Application Load Balancer (ALB) spreads the traffic and ECS Fargate runs the containers without servers to manage."}]},{"type":"heading","attrs":{"level":3,"id":"step-1-network-and-stack-skeleton"},"content":[{"type":"text","text":"Step 1. Network and stack skeleton"}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"mkdir pierogi-portal && cd pierogi-portal\nnpx aws-cdk@2 init app --language typescript"}]},{"type":"codeGroup","attrs":{"title":"CDK app, stack and network"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/bin/app.ts"},"content":[{"type":"text","text":"import { App, Tags } from 'aws-cdk-lib';\nimport { PortalStack } from '../lib/portal-stack.js';\n\nconst app = new App();\nnew PortalStack(app, 'pierogi-portal-prod', {\n  env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: 'eu-central-1' },\n  domainName: 'pierogarnia.example',\n});\n// Tags flow to every resource that supports them – the basis of cost allocation.\nTags.of(app).add('project', 'pierogi-portal');\nTags.of(app).add('env', 'prod');"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/portal-stack.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';\nimport * as ecs from 'aws-cdk-lib/aws-ecs';\nimport { Network } from './network.js';\nimport { Data } from './data.js';\nimport { Compute } from './compute.js';\nimport { Edge } from './edge.js';\nimport { AsyncWork } from './async.js';\n\nexport interface PortalStackProps extends StackProps {\n  domainName: string;\n}\n\nexport class PortalStack extends Stack {\n  constructor(scope: Construct, id: string, props: PortalStackProps) {\n    super(scope, id, props);\n    const { vpc } = new Network(this, 'Network');\n    const cluster = new ecs.Cluster(this, 'Cluster', {\n      vpc,\n      containerInsightsV2: ecs.ContainerInsights.ENHANCED,\n      enableFargateCapacityProviders: true,\n    });\n    const data = new Data(this, 'Data', { vpc });\n    const compute = new Compute(this, 'Compute', { vpc, cluster, data });\n    const jobs = new AsyncWork(this, 'Async', { cluster });\n    jobs.queue.grantSendMessages(compute.api.taskDefinition.taskRole);\n    compute.api.taskDefinition.defaultContainer?.addEnvironment('JOBS_QUEUE_URL', jobs.queue.queueUrl);\n    const edge = new Edge(this, 'Edge', { alb: compute.api.loadBalancer });\n\n    new CfnOutput(this, 'CdnDomain', { value: edge.distribution.distributionDomainName });\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/network.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport * as ec2 from 'aws-cdk-lib/aws-ec2';\n\nexport class Network extends Construct {\n  readonly vpc: ec2.Vpc;\n\n  constructor(scope: Construct, id: string) {\n    super(scope, id);\n    this.vpc = new ec2.Vpc(this, 'Vpc', {\n      ipAddresses: ec2.IpAddresses.cidr('10.20.0.0/16'),\n      maxAzs: 3, // three Availability Zones: losing one leaves two thirds of capacity\n      natGateways: 2, // one per AZ is the most resilient; 2 is a cost compromise\n      subnetConfiguration: [\n        { name: 'public', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24 },\n        { name: 'app', subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS, cidrMask: 22 },\n        { name: 'data', subnetType: ec2.SubnetType.PRIVATE_ISOLATED, cidrMask: 24 },\n      ],\n    });\n    // S3 traffic from private subnets skips the NAT gateway (and its per-GB fee).\n    this.vpc.addGatewayEndpoint('S3', { service: ec2.GatewayVpcEndpointAwsService.S3 });\n  }\n}"}]}]},{"type":"paragraph","content":[{"type":"text","text":"The VPC has three kinds of subnets: public (NAT gateways only), private with egress (API containers) and isolated (database and cache – no route to the internet at all). Three Availability Zones mean that losing one takes away a third of your capacity, not half. The S3 gateway endpoint is free and routes S3 traffic from private subnets around the NAT gateway – and its per-gigabyte fee."}]},{"type":"heading","attrs":{"level":3,"id":"step-2-the-api-on-fargate-with-autoscaling"},"content":[{"type":"text","text":"Step 2. The API on Fargate with autoscaling"}]},{"type":"codeGroup","attrs":{"title":"Fargate service, health checks and graceful shutdown"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/compute.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { Duration } from 'aws-cdk-lib';\nimport * as ec2 from 'aws-cdk-lib/aws-ec2';\nimport * as ecs from 'aws-cdk-lib/aws-ecs';\nimport * as patterns from 'aws-cdk-lib/aws-ecs-patterns';\nimport type { Data } from './data.js';\n\nexport class Compute extends Construct {\n  readonly api: patterns.ApplicationLoadBalancedFargateService;\n\n  constructor(scope: Construct, id: string, props: { vpc: ec2.IVpc; cluster: ecs.ICluster; data: Data }) {\n    super(scope, id);\n    const { db, cacheSg, cacheEndpoint } = props.data;\n\n    this.api = new patterns.ApplicationLoadBalancedFargateService(this, 'Api', {\n      cluster: props.cluster,\n      publicLoadBalancer: false, // internal ALB, reachable only through the CloudFront VPC origin\n      openListener: false, // no 0.0.0.0/0 rule – Edge allows CloudFront only\n      desiredCount: 3,\n      cpu: 512,\n      memoryLimitMiB: 1024,\n      runtimePlatform: { cpuArchitecture: ecs.CpuArchitecture.ARM64, operatingSystemFamily: ecs.OperatingSystemFamily.LINUX },\n      circuitBreaker: { rollback: true }, // a failing deployment rolls back on its own\n      taskImageOptions: {\n        image: ecs.ContainerImage.fromAsset('../app'),\n        containerPort: 3000,\n        environment: {\n          DB_WRITER_HOST: db.clusterEndpoint.hostname,\n          DB_READER_HOST: db.clusterReadEndpoint.hostname,\n          CACHE_HOST: cacheEndpoint,\n        },\n        secrets: { DB_PASSWORD: ecs.Secret.fromSecretsManager(db.secret!, 'password') },\n      },\n    });\n    this.api.targetGroup.configureHealthCheck({ path: '/health/ready', interval: Duration.seconds(15), healthyThresholdCount: 2 });\n    this.api.targetGroup.setAttribute('deregistration_delay.timeout_seconds', '30');\n\n    db.connections.allowDefaultPortFrom(this.api.service);\n    cacheSg.addIngressRule(this.api.service.connections.securityGroups[0], ec2.Port.tcp(6379));\n\n    // Horizontal autoscaling: target tracking on CPU and on requests per task.\n    const scaling = this.api.service.autoScaleTaskCount({ minCapacity: 3, maxCapacity: 40 });\n    scaling.scaleOnCpuUtilization('Cpu', {\n      targetUtilizationPercent: 60,\n      scaleOutCooldown: Duration.seconds(60),\n      scaleInCooldown: Duration.minutes(5),\n    });\n    scaling.scaleOnRequestCount('Requests', { requestsPerTarget: 1_000, targetGroup: this.api.targetGroup });\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"app/src/server.ts"},"content":[{"type":"text","text":"import express from 'express';\nimport { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';\nimport { reader, writer } from './db.js';\nimport { cache, cached } from './cache.js';\n\nconst app = express();\napp.use(express.json({ limit: '100kb' }));\nconst sqs = new SQSClient({});\nlet draining = false;\n\n// Liveness: is the process alive? Readiness: should the ALB send traffic here?\n// Keep both shallow – a database blip must not mark every task unhealthy at once.\napp.get('/health/live', (_req, res) => { res.send('ok'); });\napp.get('/health/ready', (_req, res) => { res.status(draining ? 503 : 200).send(draining ? 'draining' : 'ready'); });\n\napp.get('/api/public/menu', async (req, res) => {\n  const lang = req.query.lang === 'en' ? 'en' : 'pl';\n  const menu = await cached(`menu:${lang}`, 300, async () =>\n    (await reader.query('SELECT id, name, price FROM dishes WHERE lang = $1 ORDER BY position', [lang])).rows);\n  // CloudFront caches it for 30 s and may serve a stale copy while it refreshes.\n  res.set('Cache-Control', 'public, max-age=30, stale-while-revalidate=60').json(menu);\n});\n\napp.put('/api/admin/dishes/:id/price', async (req, res) => {\n  const price = Number(req.body.price);\n  if (!Number.isFinite(price) || price <= 0) { res.status(400).json({ error: 'invalid price' }); return; }\n  await writer.query('UPDATE dishes SET price = $1 WHERE id = $2', [price, req.params.id]);\n  // Invalidate after the commit (separate DEL calls: keys may live in different cluster slots).\n  await Promise.all(['menu:pl', 'menu:en'].map((k) => cache.del(k)));\n  // Slow side effects (search index, newsletter, PDF menu) go to the queue.\n  await sqs.send(new SendMessageCommand({\n    QueueUrl: process.env.JOBS_QUEUE_URL,\n    MessageBody: JSON.stringify({ type: 'dish.price-changed', dishId: req.params.id, price }),\n  }));\n  res.status(204).end();\n});\n\nconst server = app.listen(3000);\n\n// Before SIGTERM, ECS deregisters the task from the target group and waits for the\n// deregistration delay. Now: finish in-flight requests, close pools, exit before\n// stopTimeout (30 s by default) ends in SIGKILL.\nprocess.on('SIGTERM', () => {\n  draining = true;\n  server.close(async () => {\n    await Promise.allSettled([writer.end(), reader.end(), cache.quit()]);\n    process.exit(0);\n  });\n  setTimeout(() => process.exit(1), 25_000).unref();\n});"}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"At least 3 tasks in 3 zones.","marks":[{"type":"bold"}]},{"type":"text","text":" With two tasks, a zone failure leaves one that suddenly has to take all the traffic. This is "},{"type":"text","text":"static stability","marks":[{"type":"italic"}]},{"type":"text","text":": the spare capacity is already there, instead of hoping autoscaling kicks in during the outage."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ARM64 (Graviton)","marks":[{"type":"bold"}]},{"type":"text","text":" usually gives better price-performance than x86 – the image must be built for "},{"type":"text","text":"linux/arm64","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"circuitBreaker: { rollback: true }","marks":[{"type":"code"}]},{"type":"text","text":" – a deployment whose new tasks fail health checks rolls back to the previous version on its own."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Shallow health checks.","marks":[{"type":"bold"}]},{"type":"text","text":" If "},{"type":"text","text":"/health/ready","marks":[{"type":"code"}]},{"type":"text","text":" checks the database, a brief Aurora hiccup marks every task unhealthy at once. The ALB then routes to all targets anyway ("},{"type":"text","text":"fail open","marks":[{"type":"italic"}]},{"type":"text","text":"), but ECS starts replacing them – which deepens the outage. Deep dependency checks belong in alarms, not in the health check."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"SIGTERM is not the end of the world.","marks":[{"type":"bold"}]},{"type":"text","text":" Before sending it, ECS deregisters the task from the target group and waits "},{"type":"text","text":"deregistration_delay","marks":[{"type":"code"}]},{"type":"text","text":" – the app finishes in-flight requests, closes connection pools and exits before "},{"type":"text","text":"SIGKILL","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"stage-3-cache-layers-and-read-replicas"},"content":[{"type":"text","text":"Stage 3. Cache layers and read replicas"}]},{"type":"paragraph","content":[{"type":"text","text":"At a million users a typical portal sees 90–95% reads: the menu, opening hours, reviews. Every one of those requests that reaches the writer database is waste. We add three layers, starting closest to the user:"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Layer"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What it holds"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"TTL"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Invalidation"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"CloudFront (edge)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"public API responses, the SPA"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"seconds–minutes for the API, a year for hashed files"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"new file names, short TTL; "},{"type":"text","text":"invalidation","marks":[{"type":"italic"}]},{"type":"text","text":" only in emergencies"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"ElastiCache (Valkey)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"query results, sessions, counters"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"minutes"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"DEL","marks":[{"type":"code"}]},{"type":"text","text":" after a write (cache-aside)"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Aurora replicas"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"full data, with replication lag"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"–"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"– (usually < 100 ms of lag)"}]}]}]}]},{"type":"heading","attrs":{"level":3,"id":"step-3-cloudfront-in-front-of-s3-and-the-api"},"content":[{"type":"text","text":"Step 3. CloudFront in front of S3 and the API"}]},{"type":"codeGroup","attrs":{"title":"CloudFront distribution with OAC and a VPC origin"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/edge.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { Duration, RemovalPolicy } from 'aws-cdk-lib';\nimport * as ec2 from 'aws-cdk-lib/aws-ec2';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\nimport * as cloudfront from 'aws-cdk-lib/aws-cloudfront';\nimport * as origins from 'aws-cdk-lib/aws-cloudfront-origins';\nimport type * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';\n\nexport class Edge extends Construct {\n  readonly distribution: cloudfront.Distribution;\n\n  constructor(scope: Construct, id: string, props: { alb: elbv2.IApplicationLoadBalancer }) {\n    super(scope, id);\n    // The SPA build (index.html, hashed JS/CSS) – private bucket, read only by CloudFront.\n    const site = new s3.Bucket(this, 'Site', {\n      blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,\n      enforceSSL: true,\n      encryption: s3.BucketEncryption.S3_MANAGED,\n      removalPolicy: RemovalPolicy.RETAIN,\n    });\n\n    // Short-lived edge cache for public API reads (menu, opening hours).\n    const apiCache = new cloudfront.CachePolicy(this, 'ApiCache', {\n      defaultTtl: Duration.seconds(30),\n      minTtl: Duration.seconds(0),\n      maxTtl: Duration.minutes(5),\n      queryStringBehavior: cloudfront.CacheQueryStringBehavior.allowList('lang', 'page'),\n      enableAcceptEncodingGzip: true,\n      enableAcceptEncodingBrotli: true,\n    });\n    // Only CloudFront's origin-facing IP ranges may reach the internal ALB.\n    const cloudFrontRanges = ec2.PrefixList.fromLookup(this, 'CfOriginFacing', {\n      prefixListName: 'com.amazonaws.global.cloudfront.origin-facing',\n    });\n    props.alb.connections.allowFrom(cloudFrontRanges, ec2.Port.HTTP);\n    const api = origins.VpcOrigin.withApplicationLoadBalancer(props.alb, {\n      httpPort: 80,\n      protocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY, // see the note on end-to-end TLS\n    });\n\n    const securityHeaders = cloudfront.ResponseHeadersPolicy.SECURITY_HEADERS; // HSTS, nosniff, frame options…\n\n    this.distribution = new cloudfront.Distribution(this, 'Cdn', {\n      defaultRootObject: 'index.html',\n      defaultBehavior: {\n        origin: origins.S3BucketOrigin.withOriginAccessControl(site),\n        viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n        cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,\n        responseHeadersPolicy: securityHeaders,\n      },\n      additionalBehaviors: {\n        '/api/public/*': {\n          origin: api,\n          viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,\n          cachePolicy: apiCache,\n          originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,\n          responseHeadersPolicy: securityHeaders,\n        },\n        '/api/*': {\n          origin: api,\n          viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,\n          allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,\n          cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,\n          originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,\n          responseHeadersPolicy: securityHeaders,\n        },\n      },\n      // SPA routing: unknown paths return index.html.\n      errorResponses: [{ httpStatus: 403, responseHttpStatus: 200, responsePagePath: '/index.html', ttl: Duration.seconds(10) }],\n    });\n  }\n}"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Two things worth knowing. A "},{"type":"text","text":"VPC origin","marks":[{"type":"bold"}]},{"type":"text","text":" (since November 2024) lets CloudFront connect to an ALB in a private subnet – the load balancer has no public address, so nobody can bypass CloudFront (and its WAF rules) by attacking the ALB directly. On top of that, the ALB's security group admits only the ranges from CloudFront's managed prefix list. "},{"type":"text","text":"The ","marks":[{"type":"bold"}]},{"type":"text","text":"/api/public/*","marks":[{"type":"code"}]},{"type":"text","text":" path","marks":[{"type":"bold"}]},{"type":"text","text":" has a short cache policy (30 s by default, honouring the app's "},{"type":"text","text":"Cache-Control","marks":[{"type":"code"}]},{"type":"text","text":"), while the rest of "},{"type":"text","text":"/api/*","marks":[{"type":"code"}]},{"type":"text","text":" gets no caching and forwards headers, cookies and query strings. At 1,000 menu requests per second with a 30 s TTL, each point of presence sends roughly one request per 30 seconds per response variant to the application."}]},{"type":"callout","attrs":{"variant":"warning","title":"TLS from the edge to the ALB"},"content":[{"type":"paragraph","content":[{"type":"text","text":"In the example CloudFront talks to the internal ALB over HTTP – the traffic stays on the AWS network but is not encrypted. If audits or regulations require it (e.g. patient data in a clinic booking system, ISO 27001), add an HTTPS listener with an ACM certificate on the ALB and set "},{"type":"text","text":"protocolPolicy: HTTPS_ONLY","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"heading","attrs":{"level":3,"id":"step-4-aurora-with-a-replica-and-elasticache"},"content":[{"type":"text","text":"Step 4. Aurora with a replica and ElastiCache"}]},{"type":"codeGroup","attrs":{"title":"Aurora Serverless v2, ElastiCache Serverless and data access code"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/data.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { Duration, RemovalPolicy } from 'aws-cdk-lib';\nimport * as ec2 from 'aws-cdk-lib/aws-ec2';\nimport * as rds from 'aws-cdk-lib/aws-rds';\nimport * as elasticache from 'aws-cdk-lib/aws-elasticache';\n\nexport class Data extends Construct {\n  readonly db: rds.DatabaseCluster;\n  readonly cacheSg: ec2.SecurityGroup;\n  readonly cacheEndpoint: string;\n\n  constructor(scope: Construct, id: string, props: { vpc: ec2.IVpc }) {\n    super(scope, id);\n    const subnets = { subnetType: ec2.SubnetType.PRIVATE_ISOLATED };\n\n    // Aurora PostgreSQL: a writer and a reader in different AZs, both Serverless v2.\n    this.db = new rds.DatabaseCluster(this, 'Db', {\n      engine: rds.DatabaseClusterEngine.auroraPostgres({ version: rds.AuroraPostgresEngineVersion.VER_17_9 }),\n      vpc: props.vpc,\n      vpcSubnets: subnets,\n      credentials: rds.Credentials.fromGeneratedSecret('portal'), // password lives in Secrets Manager\n      defaultDatabaseName: 'portal',\n      writer: rds.ClusterInstance.serverlessV2('writer'),\n      readers: [rds.ClusterInstance.serverlessV2('reader1', { scaleWithWriter: true })],\n      serverlessV2MinCapacity: 0.5,\n      serverlessV2MaxCapacity: 32,\n      storageEncrypted: true,\n      backup: { retention: Duration.days(14) },\n      deletionProtection: true,\n      removalPolicy: RemovalPolicy.SNAPSHOT,\n    });\n\n    // ElastiCache Serverless (Valkey): no nodes to size, data replicated across AZs.\n    this.cacheSg = new ec2.SecurityGroup(this, 'CacheSg', { vpc: props.vpc, allowAllOutbound: false });\n    const cache = new elasticache.CfnServerlessCache(this, 'Cache', {\n      engine: 'valkey',\n      majorEngineVersion: '8',\n      serverlessCacheName: 'pierogi-portal',\n      subnetIds: props.vpc.selectSubnets(subnets).subnetIds,\n      securityGroupIds: [this.cacheSg.securityGroupId],\n      cacheUsageLimits: {\n        dataStorage: { maximum: 10, unit: 'GB' },\n        ecpuPerSecond: { maximum: 50_000 },\n      },\n    });\n    this.cacheEndpoint = cache.attrEndpointAddress;\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"app/src/db.ts"},"content":[{"type":"text","text":"import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\n// Aurora presents certificates from the Amazon RDS CA – bundle it in the image\n// (https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem).\nconst base: pg.PoolConfig = {\n  database: 'portal',\n  user: 'portal',\n  password: process.env.DB_PASSWORD,\n  ssl: { ca: readFileSync('/app/certs/rds-global-bundle.pem', 'utf8') },\n  max: 10, // 40 tasks × 10 × 2 pools = 800 connections – watch max_connections\n  idleTimeoutMillis: 30_000,\n  connectionTimeoutMillis: 2_000,\n};\n\n// Writes and reads that must see them go to the cluster (writer) endpoint...\nexport const writer = new pg.Pool({ ...base, host: process.env.DB_WRITER_HOST });\n// ...everything else to the reader endpoint, which balances across replicas.\nexport const reader = new pg.Pool({ ...base, host: process.env.DB_READER_HOST });"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"app/src/cache.ts"},"content":[{"type":"text","text":"import { Cluster } from 'iovalkey';\n\n// ElastiCache Serverless speaks cluster mode and requires TLS.\nexport const cache = new Cluster([{ host: process.env.CACHE_HOST!, port: 6379 }], {\n  dnsLookup: (address, callback) => callback(null, address),\n  redisOptions: { tls: {} },\n});\n\nconst inflight = new Map<string, Promise<unknown>>();\n\n/** Cache-aside: try the cache, otherwise load from the database and store with a TTL. */\nexport async function cached<T>(key: string, ttlSeconds: number, load: () => Promise<T>): Promise<T> {\n  const hit = await cache.get(key).catch(() => null); // cache down ≠ site down\n  if (hit) return JSON.parse(hit) as T;\n\n  // One load per key per task, even if 500 requests miss at the same moment.\n  const pending = inflight.get(key) as Promise<T> | undefined;\n  if (pending) return pending;\n  const promise = (async () => {\n    const value = await load();\n    const ttl = Math.round(ttlSeconds * (0.9 + Math.random() * 0.2)); // jitter: no synchronized expiry\n    await cache.set(key, JSON.stringify(value), 'EX', ttl).catch(() => undefined);\n    return value;\n  })().finally(() => inflight.delete(key));\n  inflight.set(key, promise);\n  return promise;\n}"}]}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant C as Client\n  participant A as API\n  participant V as Valkey\n  participant R as Aurora reader\n  participant W as Aurora writer\n  C->>A: GET /api/public/menu?lang=pl\n  A->>V: GET menu:pl\n  V-->>A: miss\n  A->>R: SELECT … FROM dishes\n  R-->>A: rows\n  A->>V: SET menu:pl EX ~300 s\n  A-->>C: 200 + Cache-Control: max-age=30\n  Note over C,W: Halina changes the price of ruskie pierogi\n  C->>A: PUT /api/admin/dishes/7/price\n  A->>W: UPDATE dishes …\n  A->>V: DEL menu:pl, DEL menu:en\n  A-->>C: 204","caption":"Cache-aside: reading the menu and invalidating after a price change"}},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The reader endpoint balances connections, not queries.","marks":[{"type":"bold"}]},{"type":"text","text":" It is a DNS record that rotates through the replicas – a connection pool opened in one moment may land on a single replica. With many API tasks it evens out statistically."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Read your own writes from the writer.","marks":[{"type":"bold"}]},{"type":"text","text":" A replica lags (usually under 100 ms). Read the \"order placed\" screen after an "},{"type":"text","text":"INSERT","marks":[{"type":"code"}]},{"type":"text","text":" from the "},{"type":"text","text":"writer","marks":[{"type":"code"}]},{"type":"text","text":" pool; the catalogue and menu from "},{"type":"text","text":"reader","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Watch the connections.","marks":[{"type":"bold"}]},{"type":"text","text":" 40 tasks × 2 pools × 10 connections = 800 connections. When autoscaling starts adding tasks, the database may run out of connections before it runs out of CPU. RDS Proxy helps here by sharing connections between clients."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The cache must not take the site down.","marks":[{"type":"bold"}]},{"type":"text","text":" A Valkey error in "},{"type":"text","text":"cached()","marks":[{"type":"code"}]},{"type":"text","text":" means a database read, not a 500. "},{"type":"text","text":"inflight","marks":[{"type":"code"}]},{"type":"text","text":" turns 500 simultaneous misses in one task into a single query (protection against a "},{"type":"text","text":"cache stampede","marks":[{"type":"italic"}]},{"type":"text","text":"), and a random ±10% TTL spreads key expiry."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"stage-4-background-work-through-a-queue"},"content":[{"type":"text","text":"Stage 4. Background work through a queue"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  API[API] -->|SendMessage| Q[[SQS: jobs]]\n  Q --> WK[Fargate workers<br/>Spot + On-Demand]\n  WK --> W[(Aurora writer)]\n  WK --> S3[(S3: PDF menu)]\n  Q -.after 5 attempts.-> DLQ[[DLQ]]","caption":"Stage 4: respond right away, do the rest in the background"}},{"type":"paragraph","content":[{"type":"text","text":"Generating the PDF menu, sending a newsletter after a price change, recomputing recommendations – none of this has to happen before the user gets a response. The API drops a message into SQS and answers in milliseconds, and workers process the queue at their own pace. The details – idempotency, DLQs, message visibility – are in the "},{"type":"text","text":"SQS tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-sqs"}}]},{"type":"text","text":"."}]},{"type":"codeGroup","attrs":{"title":"A queue and workers scaled by queue depth"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/async.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { Duration } from 'aws-cdk-lib';\nimport * as ecs from 'aws-cdk-lib/aws-ecs';\nimport * as sqs from 'aws-cdk-lib/aws-sqs';\nimport * as patterns from 'aws-cdk-lib/aws-ecs-patterns';\n\nexport class AsyncWork extends Construct {\n  readonly queue: sqs.Queue;\n\n  constructor(scope: Construct, id: string, props: { cluster: ecs.ICluster }) {\n    super(scope, id);\n    const dlq = new sqs.Queue(this, 'Dlq', { retentionPeriod: Duration.days(14) });\n    this.queue = new sqs.Queue(this, 'Jobs', {\n      visibilityTimeout: Duration.minutes(2),\n      receiveMessageWaitTime: Duration.seconds(20),\n      deadLetterQueue: { queue: dlq, maxReceiveCount: 5 },\n      encryption: sqs.QueueEncryption.SQS_MANAGED,\n    });\n\n    // Workers scale on queue depth, independently of the web tier.\n    new patterns.QueueProcessingFargateService(this, 'Worker', {\n      cluster: props.cluster,\n      queue: this.queue,\n      image: ecs.ContainerImage.fromAsset('../app', { file: 'Dockerfile.worker' }),\n      cpu: 512,\n      memoryLimitMiB: 1024,\n      minScalingCapacity: 0,\n      maxScalingCapacity: 20,\n      scalingSteps: [\n        { upper: 0, change: -1 },\n        { lower: 100, change: +2 },\n        { lower: 1_000, change: +5 },\n      ],\n      capacityProviderStrategies: [\n        { capacityProvider: 'FARGATE_SPOT', weight: 3 }, // interruptible, much cheaper\n        { capacityProvider: 'FARGATE', weight: 1 },\n      ],\n    });\n  }\n}"}]}]},{"type":"paragraph","content":[{"type":"text","text":"QueueProcessingFargateService","marks":[{"type":"code"}]},{"type":"text","text":" scales workers in steps based on "},{"type":"text","text":"ApproximateNumberOfMessagesVisible","marks":[{"type":"code"}]},{"type":"text","text":": an empty queue scales in (down to zero), more than 100 messages adds 2 tasks, more than 1,000 adds 5. The workers run mostly on "},{"type":"text","text":"Fargate Spot","marks":[{"type":"bold"}]},{"type":"text","text":" (up to 70% cheaper, but AWS can reclaim a task with a two-minute warning) – with idempotent processing an interrupted message simply returns to the queue."}]},{"type":"heading","attrs":{"level":2,"id":"autoscaling-policies"},"content":[{"type":"text","text":"Autoscaling policies"}]},{"type":"chart","attrs":{"type":"line","title":"Autoscaling over a day (illustrative data)","caption":"The number of API tasks follows traffic with a lag of minutes; the minimum of 3 tasks stays even at night.","data":{"labels":["00","02","04","06","08","10","12","14","16","18","20","22"],"series":[{"name":"Traffic (k requests/min)","values":[4,2,2,5,11,14,24,17,15,30,26,10]},{"name":"Fargate tasks","values":[3,3,3,4,8,10,18,13,11,23,20,8]}]}}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Policy"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"How it works"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"When"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Target tracking"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"keeps a metric near a target (e.g. CPU 60%, 1,000 requests per task)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the default choice for an API"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Step scaling"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"specific steps for alarm thresholds"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"queues, unusual metrics"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Scheduled"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"changes min/max at a given time"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"known peaks: Friday 5 p.m., a TV campaign"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Predictive (EC2 ASG)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"forecasts from history, scales ahead of time"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a repeating daily pattern on EC2"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Make scale-out fast (short cooldown) and scale-in cautious (5 minutes or more): a brief dip in traffic should not kill tasks you will need again a minute later. Before a known peak (a TV appearance!), raise the minimum with a scheduled action – autoscaling reacts to metrics, so it is always a few minutes behind the traffic."}]},{"type":"callout","attrs":{"variant":"info","title":"Fargate or an EC2 Auto Scaling group?"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Fargate: no servers to patch and per-task scaling, but a higher price per vCPU and no host access. An EC2 ASG (or ECS on EC2 with a capacity provider): cheaper for steady, heavy load, GPU instances, full control – at the cost of AMIs, patching and bin-packing. The same CDK stack can switch to an "},{"type":"text","text":"ec2.AutoScalingGroup","marks":[{"type":"code"}]},{"type":"text","text":" with an "},{"type":"text","text":"AsgCapacityProvider","marks":[{"type":"code"}]},{"type":"text","text":" without changing the application."}]}]},{"type":"heading","attrs":{"level":2,"id":"costs-what-grows-with-traffic"},"content":[{"type":"text","text":"Costs: what grows with traffic"}]},{"type":"chart","attrs":{"type":"bar","title":"Monthly infrastructure cost at each stage (illustrative data)","caption":"Order-of-magnitude estimate for eu-central-1, on-demand prices without discounts or the free tier. Price your own variant in the AWS Pricing Calculator.","unit":"USD/month","stacked":true,"data":{"labels":["Stage 0 (~1k)","Stage 1 (~10k)","Stage 2 (~100k)","Stage 3 (~1M)","Stage 4 (10M+)"],"series":[{"name":"Compute","values":[15,30,110,450,2200]},{"name":"Database","values":[0,30,140,650,2400]},{"name":"Cache","values":[0,0,0,120,600]},{"name":"CDN and transfer","values":[1,5,40,300,1800]},{"name":"ALB, NAT, IPv4","values":[0,0,90,160,500]}]}}},{"type":"paragraph","content":[{"type":"text","text":"Cost grows more slowly than traffic – the cost per thousand users falls from stage to stage – but some items catch people out:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"NAT Gateway","marks":[{"type":"bold"}]},{"type":"text","text":" – an hourly fee per gateway plus a fee for every gigabyte processed. Pulling images from ECR and calling AWS services from private subnets through NAT can cost more than the containers themselves. VPC endpoints (the S3 gateway endpoint is free; interface endpoints for ECR, Secrets Manager and CloudWatch Logs are billed hourly) usually pay for themselves."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Public IPv4 addresses","marks":[{"type":"bold"}]},{"type":"text","text":" have been billed since 2024 – including those on NAT gateways and load balancers."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Data transfer to the internet","marks":[{"type":"bold"}]},{"type":"text","text":" – CloudFront has a free tier and lower rates than transfer straight from an ALB or S3. Since November 2025 there are also flat monthly plans (Free, Pro, Business, Premium) covering the CDN, WAF and DDoS protection – handy for predictable traffic."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Commitment discounts","marks":[{"type":"bold"}]},{"type":"text","text":": Compute Savings Plans cover Fargate, Lambda and EC2, and since December 2025 Database Savings Plans cover Aurora, RDS, DynamoDB and ElastiCache, among others. Buy them for your stable baseline, not for peaks."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"well-architected-checking-the-architecture"},"content":[{"type":"text","text":"Well-Architected: checking the architecture"}]},{"type":"paragraph","content":[{"type":"text","text":"The AWS Well-Architected Framework is a set of questions across six pillars. Here is how our stack does:"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Pillar"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What we did"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What's next"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Operational excellence"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"IaC (CDK), automatic deployment rollback"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"runbooks, game days, alarms ("},{"type":"text","text":"separate tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-observability-and-cost"}}]},{"type":"text","text":")"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Security"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"private subnets, ALB without a public IP, secrets in Secrets Manager, encryption"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"WAF on CloudFront, "},{"type":"text","text":"least-privilege IAM","marks":[{"type":"link","attrs":{"href":"/en/articles/aws-iam-least-privilege"}}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Reliability"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"3 AZs, min. 3 tasks, Aurora with a replica, DLQ"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"backup restore tests, AZ failure drills"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Performance efficiency"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"caching at three levels, Graviton, scaling on requests"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"load tests before campaigns"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Cost optimization"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Serverless v2, Fargate Spot for workers, S3 endpoint"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Savings Plans, cost tags, budgets"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Sustainability"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Graviton, scaling to zero where possible"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"log and data retention, smaller images"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"deploy-and-verify"},"content":[{"type":"text","text":"Deploy and verify"}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"npx cdk bootstrap            # once per account and region\nnpx cdk diff                 # what will change – always before a deploy\nnpx cdk deploy pierogi-portal-prod\ncurl -sI \"https://$(aws cloudformation describe-stacks --stack-name pierogi-portal-prod \\\n  --query \"Stacks[0].Outputs[?OutputKey=='CdnDomain'].OutputValue\" --output text)/api/public/menu?lang=pl\""}]},{"type":"output","attrs":{"title":"Second menu request – a response from the CloudFront cache (example)","language":"http","content":"HTTP/2 200\ncontent-type: application/json; charset=utf-8\ncache-control: public, max-age=30, stale-while-revalidate=60\nage: 12\nx-cache: Hit from cloudfront\nvia: 1.1 3f4b6f0e2a7c1d9e8b5a.cloudfront.net (CloudFront)\nx-amz-cf-pop: WAW51-P2\nstrict-transport-security: max-age=31536000\nx-content-type-options: nosniff\nx-frame-options: SAMEORIGIN\nx-xss-protection: 1; mode=block\nreferrer-policy: strict-origin-when-cross-origin"}},{"type":"paragraph","content":[{"type":"text","text":"x-cache: Hit from cloudfront","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"age: 12","marks":[{"type":"code"}]},{"type":"text","text":" mean the response came from the Warsaw point of presence and is 12 seconds old – the application never saw it. The security headers were added by the managed "},{"type":"text","text":"SECURITY_HEADERS","marks":[{"type":"code"}]},{"type":"text","text":" policy (more in "},{"type":"text","text":"Security headers and CSP","marks":[{"type":"link","attrs":{"href":"/en/articles/security-headers-and-csp"}}]},{"type":"text","text":")."}]},{"type":"heading","attrs":{"level":2,"id":"common-mistakes"},"content":[{"type":"text","text":"Common mistakes"}]},{"type":"callout","attrs":{"variant":"danger","title":"Sessions and files in task memory"},"content":[{"type":"paragraph","content":[{"type":"text","text":"A cart in process memory or a photo saved to the container's disk works with one task. With three, users \"lose\" their cart on every other request, and files vanish after a deployment. Sessions go to ElastiCache or tokens, files to S3 – before you turn on autoscaling."}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Autoscaling without a database connection budget","marks":[{"type":"bold"}]},{"type":"text","text":" – 40 tasks with large pools exhaust "},{"type":"text","text":"max_connections","marks":[{"type":"code"}]},{"type":"text","text":" faster than any traffic does."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A cache without an invalidation plan","marks":[{"type":"bold"}]},{"type":"text","text":" – users see the old price for an hour. Versioned keys, short TTLs and "},{"type":"text","text":"DEL","marks":[{"type":"code"}]},{"type":"text","text":" after writes."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"One Availability Zone \"because it's cheaper\"","marks":[{"type":"bold"}]},{"type":"text","text":" – saving a few tens of dollars ends in hours of downtime when the zone fails."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Deep health checks","marks":[{"type":"bold"}]},{"type":"text","text":" – the ALB and ECS take healthy tasks out because the database had a bad second."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"No load test before a peak","marks":[{"type":"bold"}]},{"type":"text","text":" – tools like k6 or Artillery against a staging environment will find the bottleneck before television does."}]}]}]},{"type":"prosCons","attrs":{"pros":["no servers to patch, per-task scaling in seconds to minutes","the same app from 3 to hundreds of copies, with no code changes","mature integrations: Secrets Manager, CloudWatch, X-Ray/OpenTelemetry"],"cons":["a higher price per vCPU than EC2 under steady, high load","for low traffic, App Runner, Lambda or a single machine is cheaper and simpler","cold start of new tasks (image pull) – minutes, not milliseconds"],"prosTitle":"Containers on Fargate behind an ALB","consTitle":"When it's too much or too little"}},{"type":"heading","attrs":{"level":2,"id":"test-yourself"},"content":[{"type":"text","text":"Test yourself"}]},{"type":"quiz","attrs":{"question":"After enabling autoscaling, the API starts returning \"too many connections\" errors although database CPU is low. What do you do first?","multiple":false,"options":[{"text":"Move Aurora to a bigger instance class","correct":false,"explanation":"A bigger instance has a higher `max_connections`, but the problem returns at the next scale-out."},{"text":"Cap the connection pools per task and add RDS Proxy","correct":true,"explanation":"Yes – the connection count grows linearly with tasks, and the proxy shares them."},{"text":"Turn off autoscaling","correct":false,"explanation":"That removes the symptom at the cost of availability at peak."}]}},{"type":"quiz","attrs":{"question":"Why is the ALB internal in this stack, with CloudFront connecting through a VPC origin?","multiple":false,"options":[{"text":"Because an internal ALB is cheaper","correct":false,"explanation":"The price is the same."},{"text":"So nobody can bypass CloudFront and WAF by attacking the ALB directly","correct":true,"explanation":"Yes – the load balancer has no public address, and its security group admits only CloudFront's ranges."},{"text":"Because CloudFront does not support public ALBs","correct":false,"explanation":"It does – a VPC origin is simply the safer option."}]}},{"type":"details","content":[{"type":"detailsSummary","content":[{"type":"text","text":"Interview question: design the backend for a portal that peaks at 50k requests per second, 95% of them reads."}]},{"type":"detailsContent","content":[{"type":"paragraph","content":[{"type":"text","text":"A good answer starts with questions: what is the traffic profile (peaks, geography), which data may be stale and for how long, what are the availability requirements. Then the layers: a CDN for static files and public reads with a short TTL (most traffic ends at the edge), a stateless API in several zones behind a load balancer autoscaling on requests, cache-aside in Redis/Valkey with invalidation on write and stampede protection, a database with read replicas and deliberate routing of \"read your own writes\" to the writer, connection pooling (RDS Proxy). Writes and slow operations go asynchronously through a queue with idempotent workers. Plus: static stability (headroom for losing a zone), metrics and alarms on p99 and errors, load tests, a cost estimate. The candidate who brings up data partitioning or multi-region only when the requirements justify it – not \"because Netflix does\" – does best."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"what-s-next"},"content":[{"type":"text","text":"What's next"}]},{"type":"linkCard","attrs":{"url":"/en/articles/aws-s3-bucket-security","title":"S3 bucket security","description":"Block Public Access, KMS, OAC, Object Lock and presigned URLs","kind":"article","ref":"aws-s3-bucket-security"}},{"type":"linkCard","attrs":{"url":"/en/articles/aws-iam-least-privilege","title":"IAM and least privilege","description":"Roles for ECS tasks, OIDC for GitHub Actions, Access Analyzer","kind":"article","ref":"aws-iam-least-privilege"}},{"type":"linkCard","attrs":{"url":"/en/articles/aws-observability-and-cost","title":"Observability and cost","description":"Alarms, OpenTelemetry, budgets and cost anomaly detection","kind":"article","ref":"aws-observability-and-cost"}},{"type":"linkCard","attrs":{"url":"/en/topics/aws-scalability","title":"Scalable portals on AWS","description":"Everything about scaling","kind":"topic","ref":"aws-scalability"}}]},"toc":[{"id":"the-rule-scale-what-hurts","text":"The rule: scale what hurts","level":2,"locked":false},{"id":"stage-0-one-server","text":"Stage 0. One server","level":2,"locked":false},{"id":"stage-1-a-separate-database-and-static-files-at-the-edge","text":"Stage 1. A separate database and static files at the edge","level":2,"locked":false},{"id":"stage-2-a-stateless-api-behind-a-load-balancer-in-three-zones","text":"Stage 2. A stateless API behind a load balancer in three zones","level":2,"locked":false},{"id":"step-1-network-and-stack-skeleton","text":"Step 1. Network and stack skeleton","level":3,"locked":false},{"id":"step-2-the-api-on-fargate-with-autoscaling","text":"Step 2. The API on Fargate with autoscaling","level":3,"locked":false},{"id":"stage-3-cache-layers-and-read-replicas","text":"Stage 3. Cache layers and read replicas","level":2,"locked":false},{"id":"step-3-cloudfront-in-front-of-s3-and-the-api","text":"Step 3. CloudFront in front of S3 and the API","level":3,"locked":false},{"id":"step-4-aurora-with-a-replica-and-elasticache","text":"Step 4. Aurora with a replica and ElastiCache","level":3,"locked":false},{"id":"stage-4-background-work-through-a-queue","text":"Stage 4. Background work through a queue","level":2,"locked":false},{"id":"autoscaling-policies","text":"Autoscaling policies","level":2,"locked":false},{"id":"costs-what-grows-with-traffic","text":"Costs: what grows with traffic","level":2,"locked":false},{"id":"well-architected-checking-the-architecture","text":"Well-Architected: checking the architecture","level":2,"locked":false},{"id":"deploy-and-verify","text":"Deploy and verify","level":2,"locked":false},{"id":"common-mistakes","text":"Common mistakes","level":2,"locked":false},{"id":"test-yourself","text":"Test yourself","level":2,"locked":false},{"id":"what-s-next","text":"What's next","level":2,"locked":false}],"locked":false,"paywall":null,"previewRatio":0.3,"totalBlocks":71,"visibleBlocks":71,"resources":[{"id":"6b0857b43c96f2d34d0b3849","type":"article","provider":"web","url":"https://highscalability.com/blog/2016/1/11/a-beginners-guide-to-scaling-to-11-million-users-on-amazons.html","embedUrl":null,"title":"A Beginner's Guide to Scaling to 11M+ Users on Amazon's AWS","description":"How do you scale a system from one user to more than 11 million users? Joel Williams , Amazon W...","author":"@highscal","thumbnailUrl":"https://c2.staticflickr.com/2/1546/23690555693_2aa3c8c0f1_o.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["cloud","hacker-news"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"hn","publishedAt":"2016-01-12T05:29:09.000Z","popularity":76,"verifiedAt":"2026-11-26T11:19:38.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:51.221Z","updatedAt":"2026-11-26T16:00:51.221Z"},{"id":"6b0857bf3c96f2d34d0b42b8","type":"article","provider":"web","url":"https://docs.aws.amazon.com/wellarchitected/latest/framework/welcome.html","embedUrl":null,"title":"AWS Well-Architected Framework - AWS Well-Architected Framework","description":"The AWS Well-Architected Framework helps you understand the pros and cons of decisions you make while building systems on AWS. Using the Framework helps you learn architectural best practices for designing and operating secure, reliable, efficient, cost-effective, and sustainable workloads in the…","author":"AWS Well-Architected Framework","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["cloud"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":60,"verifiedAt":"2026-11-26T11:26:15.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857bf3c96f2d34d0b4267","type":"article","provider":"web","url":"https://aws.amazon.com/builders-library/caching-challenges-and-strategies","embedUrl":null,"title":"Caching challenges and strategies | AWS Builder Center","description":"ARCHITECTURE | LEVEL 300","author":"Amazon Builders' Library","thumbnailUrl":"https://builder.aws.com/assets/og-hiXAX-on.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["aws","distributed-systems","cloud"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":"2019-12-05T12:00:00.000Z","popularity":65,"verifiedAt":"2026-11-26T11:25:41.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857bf3c96f2d34d0b428c","type":"article","provider":"web","url":"https://aws.amazon.com/builders-library/static-stability-using-availability-zones","embedUrl":null,"title":"Static stability using Availability Zones | AWS Builder Center","description":"ARCHITECTURE | LEVEL 300","author":"Amazon Builders' Library","thumbnailUrl":"https://builder.aws.com/assets/og-hiXAX-on.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["aws","distributed-systems","cloud"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":"2019-12-05T12:00:00.000Z","popularity":65,"verifiedAt":"2026-11-26T11:25:39.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857bf3c96f2d34d0b4275","type":"article","provider":"web","url":"https://aws.amazon.com/builders-library/implementing-health-checks","embedUrl":null,"title":"Implementing health checks | AWS Builder Center","description":"How Amazon implements health checks, from shallow to deep, to detect failures, remove bad hosts from service, and avoid cascading outages.","author":"Amazon Builders' Library","thumbnailUrl":"https://builder.aws.com/assets/og-hiXAX-on.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["aws","distributed-systems","cloud"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":"2019-12-05T12:00:00.000Z","popularity":65,"verifiedAt":"2026-11-26T11:25:41.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857bf3c96f2d34d0b4296","type":"article","provider":"web","url":"https://learn.microsoft.com/en-us/azure/architecture/patterns/cache-aside","embedUrl":null,"title":"Cache-Aside Pattern","description":"Learn how to load data on demand into a cache, which can improve performance and maintain consistency between cached data and the underlying data store.","author":"Microsoft Azure Architecture Center","thumbnailUrl":"https://learn.microsoft.com/en-us/media/open-graph-image.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["azure","cloud","performance"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":64,"verifiedAt":"2026-11-26T11:07:42.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"}],"challenges":[],"attachments":[],"hasCode":true,"repoUrl":null,"series":[],"prev":null,"next":null,"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":104,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":90},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":61},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":59},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":46}]}}