akshat porwal

AI Engineering
Cloud & DevOps
Solutions Architecture
Fintech

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.

Architecture overview
PresentationApplicationData collectionDocument processingData and notificationsAnalysisDeployment and monitoringUserCloudFront + S3Load balancerFastAPI · EC2PostgreSQL · RDSEventBridgeDiscovery · SQSDiscovery · EC2Download · SQSDownload · EC2S3 documentsS3 eventAnalysis · SQSAnalysis · EC2ClassificationAmazon BedrockFinBERTProcessed resultsNotify · SQSNotifications · EC2Email providerPostgreSQL · RDSSource controlCloudWatchCloudFormationDead-letter queueExternal sources
Select or focus a component to explore its role and connections.

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

Architecture overview
PresentationApplicationData collectionDocument processingData and notificationsAnalysisDeployment and monitoringUserStatic Web AppsApplication GatewayFastAPI · VM scale setAzure PostgreSQLLogic Apps scheduleDiscovery · Service BusDiscovery · VMDownload · Service BusDownload · VMBlob StorageEvent GridAnalysis · Service BusAnalysis · VMClassificationSummarisationFinBERTProcessed resultsNotify · Service BusNotifications · VMEmail providerAzure PostgreSQLSource controlAzure MonitorInfrastructure as codeDead-letter queueExternal sources
Select or focus a component to explore its role and connections.

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

Architecture overview
PresentationApplicationData collectionDocument processingData and notificationsAnalysisDeployment and monitoringUserStatic Web AppsAPI endpointFastAPI · FunctionsAzure PostgreSQLTimer triggerDiscovery · Service BusDiscovery · FunctionsDownload · Service BusDownload · FunctionsBlob StorageEvent GridAnalysis · Service BusAnalysis · FunctionsClassificationSummarisationFinBERTProcessed resultsNotify · Service BusNotify · FunctionsEmail providerAzure PostgreSQLSource controlAzure MonitorInfrastructure as codeDead-letter queueExternal sources
Select or focus a component to explore its role and connections.

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.

ResponsibilityAzure pathwayAWS counterpart
Static frontendStatic Web Apps; Front Door is an optional edge layerS3 and CloudFront
API entry and executionAPI Management is optional; Functions or a VM scale set runs the APIAPI Gateway and Lambda, or an Application Load Balancer and EC2
Scheduled workFunctions timer trigger or a scheduled workflowEventBridge Scheduler
Queues and failure handlingService Bus queues and dead-letter subqueuesSQS queues and dead-letter queues
Original documents and eventsBlob Storage and Event GridS3 and S3 event notifications
Relational dataAzure Database for PostgreSQL or retain SupabaseRDS for PostgreSQL or retain Supabase
Longer container workContainer Apps jobsECS tasks on Fargate
Secrets and identityKey Vault and managed identitiesSecrets Manager or Parameter Store and IAM roles
ObservabilityAzure Monitor and Application InsightsCloudWatch 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

Architecture overview
PresentationApplicationData collectionDocument processingData and notificationsAnalysisDeployment and monitoringUserCloud StorageCloud Load BalancingFastAPI · Compute EngineCloud SQL · PostgreSQLCloud SchedulerDiscovery · Pub/SubDiscovery · VMDownload · Pub/SubDownload · VMCloud StoragePub/Sub notificationAnalysis · Pub/SubAnalysis · VMClassificationVertex AIFinBERTProcessed resultsNotify · Pub/SubNotifications · VMEmail providerCloud SQL · PostgreSQLSource controlCloud MonitoringCloud BuildDead-letter topicExternal sources
Select or focus a component to explore its role and connections.

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

Architecture overview
PresentationApplicationData collectionDocument processingData and notificationsAnalysisDeployment and monitoringUserCloud StorageHTTPS endpointFastAPI · Cloud RunCloud SQL · PostgreSQLCloud SchedulerDiscovery · Pub/SubDiscovery · Cloud RunDownload · Pub/SubDownload · Cloud RunCloud StorageEventarcAnalysis · Cloud RunClassificationVertex AIFinBERTProcessed resultsNotify · Pub/SubNotify · Cloud RunEmail providerCloud SQL · PostgreSQLSource controlCloud MonitoringCloud BuildDead-letter topicExternal sources
Select or focus a component to explore its role and connections.

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.

ResponsibilityGoogle Cloud pathwayAWS counterpart
Web traffic and APICloud Load Balancing and Compute Engine, or a Cloud Run serviceApplication Load Balancer and EC2, or API Gateway and Lambda
Scheduled collectionCloud SchedulerEventBridge Scheduler
MessagingPub/Sub topics and subscriptionsSQS queues
File storage and eventsCloud Storage and Eventarc or Pub/Sub notificationsS3 and S3 event notifications
Structured databaseCloud SQL for PostgreSQLRDS for PostgreSQL
Task-driven containersCloud Run jobsECS tasks on Fargate
Model servicesVertex AI, subject to model and API evaluationAmazon Bedrock
ObservabilityCloud Logging and Cloud MonitoringCloudWatch

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.