Building Portable Cloud Functions with Spring Cloud Function and Hexagonal Architecture - Part 3 (Azure)
In Part 1, we built a Task Management System using Spring Cloud Function and Hexagonal Architecture, deploying it to Google Cloud Functions with Firestore. In Part 2, we proved the architecture by deploying the exact same domain code to AWS Lambda with DynamoDB. Now, we complete the trifecta: the same business logic running on Azure Functions with Cosmos DB.
No domain logic modifications. No business rule changes. Just infrastructure swapping.
This is the power of true cloud portability.
Recap: What We Built
Our Task Management System implements comprehensive business rules:
Create Operations:
Read/Update/Delete Operations:
These rules live in our domain layer, completely cloud-agnostic.
The Azure Implementation Strategy
What Stays the Same (Zero Changes)
What Changes (Infrastructure Only)
Azure-Specific Implementation
1. Maven Dependencies
The project uses Spring Cloud Azure with a profile-based approach:
2. Cosmos DB Document Mapping
Azure Cosmos DB uses a document-based model with partition keys for scalability:
Key differences from other cloud providers:
3. Cosmos DB Repository Implementation
Key points:
4. Spring Data Cosmos Repository Interface
Unlike AWS Lambda and GCP Cloud Functions that work seamlessly with Spring Cloud Function's FunctionInvoker, Azure Functions requires a custom handler that bridges HTTP triggers to Spring Cloud Function beans:
Key implementation details:
6. Application Configuration
Recommended by LinkedIn
Infrastructure as Code: Terraform for Azure
Main Resources
Deployment Process
Build and Deploy
Testing in Action
Function Routing
Spring Cloud Function uses a routing mechanism to direct requests:
Business Rules Validation
Key Benefits Demonstrated
1. Pure Business Logic
The domain layer contains no Azure-specific code. Rules like "max 5 high-priority tasks per day" are expressed in pure Java.
2. Testable Architecture
3. Infrastructure Flexibility
Swapping between GCP Firestore, AWS DynamoDB, and Azure Cosmos DB requires only:
The Power of True Portability
Our Azure implementation completes the trilogy and proves that Hexagonal Architecture + Spring Cloud Function delivers on its promise:
Get Started
Ready to deploy the same Task Management System to Azure Functions?
🔗 Complete source code: GitHub Repository
Repository Structure - Complete Multi-Cloud
Quick Commands Reference
Three clouds, one codebase, infinite possibilities.
Follow me to get notified about future articles! Have questions about the Azure implementation? Drop them in the comments below.
⭐ Star the GitHub repo if you found this series valuable!
This is such a clean example of why hexagonal architecture pays off in the real world. “One codebase, three clouds, zero business logic changes” is the kind of portability claim most teams don’t actually achieve. What was the trickiest part of the Azure Functions + Cosmos DB adapter compared to AWS/GCP?