Stonks-in-Hand / 03
Cloud pathways.
Server-based and serverless approaches across AWS, Azure and Google Cloud.
AWS server-based pathway
A more complete EC2 design, extending the original server-based option.
Request path
A possible resilient design places an Application Load Balancer in front of multiple stateless FastAPI instances in an EC2 Auto Scaling group. Health checks remove unhealthy instances from traffic; instances can be distributed across availability zones where the availability goal justifies it.
The frontend can be delivered separately with S3 and CloudFront when it is a static export. Server-rendered Next.js requires a compatible server runtime rather than static object storage alone.
Background work and data
Use SQS to separate discovery, download, analysis and notifications from the request path. Dedicated workers can run independently of API instances; S3 holds raw documents and PostgreSQL stores structured application data. A managed RDS deployment can provide backup and recovery options, selected against explicit recovery requirements.
Operational choices
Define network boundaries, TLS, least-privilege roles, secrets, instance patching, health checks, logs, alarms and backup recovery before sizing the system. Load balancers, multiple instances, NAT and managed databases all add cost; start with availability requirements and a workload model rather than assuming maximum redundancy is free.
Why a load balancer?
A load balancer is the entry point for HTTP traffic to a pool of API servers. It checks instance health and forwards requests to healthy targets; an Auto Scaling group can replace unhealthy instances and adjust capacity. These are complementary jobs: routing traffic does not itself decide the required size of the server fleet.
Keep API servers stateless where practical, and run discovery and analysis in separate worker pools. This allows web traffic and background work to scale for different reasons. Queues are still useful with servers: server-based compute does not require every job to run inside the web request.
AWS serverless pathway
An event-driven design for independent stages, retries and asynchronous delivery.
Flow
EventBridge starts discovery; SQS buffers work for discovery and download. Downloaded files go to S3, whose events initiate queued analysis. Lambda functions classify documents, use Bedrock for summarisation and run sentiment analysis; a separate notification stage sends watchlist alerts.
API Gateway and FastAPI serve application requests independently of the background pipeline. S3 and CloudFront deliver the static frontend; Supabase PostgreSQL holds structured data.
Failure and recovery
A queue and dead-letter queue provide a way to isolate repeatedly failing work for investigation. SQS-triggered Lambda processing can deliver a message more than once, so handlers must be idempotent. Configure visibility timeouts, retries, concurrency and partial batch failures to suit each stage.
Boundaries
Lambda execution limits, browser dependencies, document size and external API quotas all affect how work is split. For tasks that do not fit the execution model, evaluate a container worker or another managed execution option. Logs, traces, queue age, dead-letter depth and cost alarms make the distributed workflow observable.
Working within limits
Lambda is suitable when a stage can finish within its execution and packaging constraints. A browser-based download, a large document or an NLP model can require more time, memory or dependencies than a short function comfortably supports. Container workers are an alternative for that stage; the surrounding queue and storage boundaries can remain.
Monitor the age of queued work as well as function errors: a worker can be healthy while work accumulates faster than it is processed. Track retries, dead-letter depth, processing duration and the status of individual runs to make failures visible across the pipeline.
Azure pathways
Two ways to map the same workload to Azure services.
Server-based
A candidate design uses Application Gateway in front of a Virtual Machine Scale Set for stateless API instances. A separate worker pool consumes queued collection and analysis work; Blob Storage keeps raw documents and Azure Database for PostgreSQL holds structured records. Configure private networking, managed identities, health checks, monitoring and backups to match the availability target.
Serverless
A candidate event-driven path uses Azure Functions for API and background handlers, Azure Service Bus for queued work, Blob Storage for documents and Azure Database for PostgreSQL for relational data. Azure-hosted AI services can be evaluated for summarisation against the same output, security and cost criteria used for AWS.
Match function hosting limits to browser automation and document analysis. For longer tasks, assess Azure Container Apps jobs or a worker rather than assuming every workload fits a function invocation.
Comparison
VMs provide OS and runtime control but require patching and capacity management. Functions reduce server administration for event-driven work, while adding distributed integration and execution constraints. Estimate costs using the same region, traffic, document volume, storage and availability assumptions as the AWS options.
Service mapping
The services below perform comparable jobs in the two designs. They are functional analogues, so their configuration, delivery behaviour and limits still need independent evaluation.
| Responsibility | Azure pathway | AWS counterpart |
|---|---|---|
| Static frontend | Static Web Apps; Front Door is an optional edge layer | S3 and CloudFront |
| API entry and execution | API Management is optional; Functions or a VM scale set runs the API | API Gateway and Lambda, or an Application Load Balancer and EC2 |
| Scheduled work | Functions timer trigger or a scheduled workflow | EventBridge Scheduler |
| Queues and failure handling | Service Bus queues and dead-letter subqueues | SQS queues and dead-letter queues |
| Original documents and events | Blob Storage and Event Grid | S3 and S3 event notifications |
| Relational data | Azure Database for PostgreSQL or retain Supabase | RDS for PostgreSQL or retain Supabase |
| Longer container work | Container Apps jobs | ECS tasks on Fargate |
| Secrets and identity | Key Vault and managed identities | Secrets Manager or Parameter Store and IAM roles |
| Observability | Azure Monitor and Application Insights | CloudWatch and, where used, X-Ray |
Reading the diagram
For the VM pathway, Application Gateway distributes web requests to API instances in a Virtual Machine Scale Set. A separate pool can consume Service Bus messages. For the serverless pathway, Functions can respond to HTTP, timers and queue messages; Event Grid can route a Blob Storage event into downstream processing.
API Management is an optional policy and routing layer, not the place where FastAPI executes. Managed PostgreSQL provides the database engine but is not a replacement for every Supabase feature. Container Apps jobs can be considered for heavier workloads without requiring all stages to move to containers.
Google Cloud pathways
VM and managed-container designs for the same collection and analysis pipeline.
Server-based
A candidate design places an external Application Load Balancer in front of a Compute Engine managed instance group running stateless APIs. Separate workers process queued work, Cloud Storage holds raw documents and Cloud SQL for PostgreSQL stores relational records. Health checks, autoscaling, backups and availability-zone choices follow the workload’s reliability goals.
Serverless
A candidate design uses Cloud Run services for the API and event handlers, Cloud Run jobs for task-driven work, Pub/Sub for events, Cloud Scheduler for scheduled collection, Cloud Storage for files and Cloud SQL for PostgreSQL. Vertex AI is an option to evaluate for summarisation.
Choose the appropriate Cloud Run resource for request-driven, task-driven or background processing, and account for database connections, job duration, retries and downstream quotas.
Comparison
Compute Engine offers control over the machine and long-running processes, alongside operating-system and scaling responsibility. Managed containers reduce infrastructure management but require careful resource, execution and network configuration. Compare using a shared workload and region; do not treat service equivalence as a cost estimate.
Service mapping
This mapping describes the same responsibilities using Google Cloud services. The managed-container pathway uses Cloud Run services for request and event handlers and can use Cloud Run jobs for task-driven work.
| Responsibility | Google Cloud pathway | AWS counterpart |
|---|---|---|
| Web traffic and API | Cloud Load Balancing and Compute Engine, or a Cloud Run service | Application Load Balancer and EC2, or API Gateway and Lambda |
| Scheduled collection | Cloud Scheduler | EventBridge Scheduler |
| Messaging | Pub/Sub topics and subscriptions | SQS queues |
| File storage and events | Cloud Storage and Eventarc or Pub/Sub notifications | S3 and S3 event notifications |
| Structured database | Cloud SQL for PostgreSQL | RDS for PostgreSQL |
| Task-driven containers | Cloud Run jobs | ECS tasks on Fargate |
| Model services | Vertex AI, subject to model and API evaluation | Amazon Bedrock |
| Observability | Cloud Logging and Cloud Monitoring | CloudWatch |
Reading the diagram
Cloud Scheduler can start collection on a schedule, Pub/Sub can distribute messages between services, and Cloud Storage keeps original files. Eventarc can route a storage event to a Cloud Run receiver. Pub/Sub delivery and subscription semantics differ from SQS, so retry, duplicate handling and dead-letter configuration should be designed for the chosen service.
A Cloud Run service receives requests or events; a Cloud Run job runs a task to completion. Choosing between them depends on how the work is triggered and how long it needs to run. Cloud SQL remains a separate relational database and needs connection and capacity planning.