AWS re:Invent 2024 – Zero to production serverless in 8 weeks
In early 2024, we embarked on an exciting but challenging project at Chemist4U, the UK’s third-largest online pharmacy dispensing an impressive 175,000–200,000 items monthly. Our mission? To build a secure, scalable integration for a clinic specializing in ADHD diagnostics and treatment. This new system would replace the clinic’s existing pharmacy partner, which struggled to scale alongside their growing demand.
With tight deadlines and high stakes, this project was a race against time to ensure patients could continue receiving critical medications without any interruption. Here’s how we made it happen! 💪
🎯 The Challenge: What Did We Need to Solve?
We were tasked with building a comprehensive solution that tackled:
- Secure Data Integration: A safe, reliable way to transfer sensitive patient and prescription data.
- Regulatory Compliance: ADHD medications are highly controlled, requiring checks on patient history and strict adherence to UK regulations.
- Seamless Payment Handling: Private prescriptions needed secure payment processing, while NHS prescriptions required accurate invoicing for reimbursements.
- Customer Service Enablement: Equipping the support team with tools to answer patient inquiries effectively.
- Warehouse Integration: Ensuring prescriptions were processed smoothly by our ERP and warehouse systems.
Deadline: Eight weeks ⏳
🔧 Why Serverless?
Given the complexity and urgency, serverless architecture was the perfect choice. Here’s why:
- ⚙️ Built-in High Availability: No need to manage uptime—it’s baked in.
- 📉 Low Administration Overhead: Skip the headache of managing EC2 instances or Kubernetes.
- 🚀 Rapid Development: Tools like AWS CDK allowed us to prototype and deploy features faster.
- 📈 Auto Scaling: Effortlessly handle peaks and troughs in prescription volume.
Curious about serverless? Check out AWS’s guide to serverless architecture. 🌟
💡 The Approach: Prototyping First
We skipped the proof of concept stage and dove straight into building a working prototype. Prototyping allowed us to test our ideas in real-world conditions while leaving room for rapid iterations.
🛠 Tools and Technologies
- AWS CDK: For Infrastructure as Code (IaC).
- Vitest: Unit testing from Day 1 ensured reliability.
- Biome: Automated linting and formatting saved valuable time.
- Hexagonal Architecture: Enabled modular development—essential for teamwork!
- Serverless Framework: Combined with AWS Lambda, API Gateway, and DynamoDB for backend functionality.
- React with Vite: For the front-end interface.
🎉 Day 1 Wins!
By leveraging pre-built boilerplate code and automation tools, we launched:
- A basic authenticated website using AWS Cognito.
- A stubbed API with validation powered by API Gateway.
- CI/CD pipelines for automated deployments.
- Fully isolated developer environments for efficient parallel work.
🏗️ Building the Core Integration
The centerpiece of the system was the integration with the clinic’s existing platform. Here’s how we approached it:
1️⃣ Defining Interfaces Early
To avoid delays, we deployed a stubbed API with validation using Swagger. This allowed the clinic’s team to proceed with development in parallel.
2️⃣ Validation Handling
Initially, we used API Gateway’s built-in validation. However, the generic error messages were a bottleneck during testing. Switching to Zod gave us:
- Customizable validation messages.
- Consistent logic reuse in TypeScript.
- Cleaner, more actionable error handling.
⚡ Infrastructure Setup with AWS CDK
Our serverless architecture consisted of:
- API Gateway: Managed RESTful API endpoints.
- Lambda Functions: Executed core business logic.
- DynamoDB: Stored prescription and patient data securely.
- S3 Buckets: Hosted the React front end and stored documents.
Want to learn CDK? Check out this CDK documentation. 📚
🌈 Rapid Iterations with Serverless
Serverless enabled us to:
- Quickly deploy isolated development environments.
- Make reproducible changes using IaC.
- Maintain stability with automated tests.
🛠 Lessons Learned
💡 Prototyping is Key: Starting with a working prototype minimized rework.
💡 Better Error Handling Matters: Switching to Zod drastically improved testing efficiency.
💡 Serverless Speeds Things Up: By offloading infrastructure management, we could focus on delivering business value.
🎯 The Result
In just 8 weeks, we delivered a fully functional system that:
- Secured sensitive patient data 🔒.
- Automated workflows adhering to strict regulations ✅.
- Integrated seamlessly with the clinic and warehouse systems ⚡.
- Scaled to meet the growing demand for ADHD prescriptions 📈.
📺 Original Video
Want to dive deeper into our process? Watch the original video on YouTube:
What do you think of our approach? Have you worked on similar tight-deadline projects? Let us know in the comments! 👇