Kevyn Franco • November 25, 2025 • 20 min read
Architecting for Resilience: Lessons Learned from Building a Global Distributed System
In a world where uptime and performance are paramount, building resilient distributed systems presents unique challenges. This article delves into architectural decisions made while scaling a system to handle millions of users and petabytes of data, complete with trade-offs, performance benchmarks, and hard-won lessons from real-world incidents.
Architecting for Resilience: Lessons Learned from Building a Global Distributed System
Introduction
In my tenure at a leading tech company, I faced a critical challenge: architecting a distributed system capable of handling millions of users while ensuring high availability and low latency. This article explores the architectural decisions I made, their trade-offs, and the performance implications we encountered.
Problem Statement
Our goal was to design a system that could scale to support a global audience while maintaining a consistent user experience. We were processing over 50 million requests per day, with a growing user base leading to increasing data demands. The challenge was to ensure our system remained performant and resilient against failures.
Architectural Decisions and Trade-offs
Initial Architecture
We started with a microservices architecture, leveraging AWS ECS for container orchestration. Each service was stateless to facilitate scaling. Our initial stack included:
- DynamoDB for data storage with eventual consistency.
- Redis for caching frequently accessed data.
- Kafka for event streaming between services.
Trade-offs
- Microservices provided agility but introduced complexity in inter-service communication.
- Eventual Consistency with DynamoDB led to stale reads, necessitating careful design considerations in user-facing services.
Scaling Strategy
As traffic increased, we implemented sharding in DynamoDB to distribute read/write loads. The sharding key was chosen based on user IDs to ensure even distribution.
Performance Implications
By applying sharding, we achieved a 95th percentile read latency of 12ms, compared to 45ms before sharding. However, this introduced complexity regarding cross-shard queries, which required redesigning service interactions.
Caching Layers
To mitigate latency further, we introduced a multi-tier caching strategy using Redis. We opted for Redis Cluster to distribute cache across multiple nodes, achieving:
- Cache hit rate: 85%
- Response time: 3ms for cache hits compared to 50ms for direct DynamoDB access.
Handling Partition Tolerance
We faced several incidents where network partitions affected service availability. This led to adopting the CAP theorem more seriously. We decided to prioritize availability and partition tolerance, accepting temporary inconsistencies.
Performance Benchmarking
Before and After Metrics
| Metric | Before Optimization | After Optimization | |--------------------------------|---------------------|--------------------| | 95th Percentile Read Latency | 45ms | 12ms | | 95th Percentile Write Latency | 80ms | 20ms | | Cache Hit Rate | N/A | 85% | | Throughput (requests/sec) | 500 | 800 |
Code Example: Implementing Redis Caching
Here’s an example of how we implemented Redis caching in our Node.js service:
const redis = require('redis');
const client = redis.createClient();
async function getUserData(userId) {
const cacheKey = `user:${userId}`;
const cachedData = await client.get(cacheKey);
if (cachedData) {
return JSON.parse(cachedData);
}
const userData = await fetchUserDataFromDB(userId);
client.setex(cacheKey, 3600, JSON.stringify(userData)); // Cache for 1 hour
return userData;
}
Lessons Learned from Production Incidents
One incident involved a DynamoDB throttling issue due to hot partitions. We discovered that the shard key caused an uneven distribution of writes, leading to 50% of writes going to a single shard.
Action Taken
We re-evaluated our sharding strategy, moving to a composite key that included timestamp in addition to user ID, enabling a more uniform distribution. After this change, we observed a 50% reduction in throttling errors.
Advanced System Design Considerations
Consistency Models
While eventual consistency worked for many use cases, we introduced a CQRS (Command Query Responsibility Segregation) pattern for user-related operations that required strong consistency. The command side writes to a separate data store with strong consistency guarantees (using PostgreSQL), while the query side remains powered by DynamoDB, ensuring we balance performance with data reliability.
Security Implications
With distributed systems, security complexity increases. We adopted a Zero Trust Architecture, where every request is authenticated and authorized regardless of the source. This included using JWT tokens for service-to-service communication and strict IAM roles in AWS.
Future Trends and Predictions
As systems evolve, I foresee several trends:
- Increased adoption of service meshes (like Istio) to manage microservices communication, improving security and observability.
- Greater reliance on serverless architectures for handling burst traffic, reducing operational overhead.
- Enhanced focus on multi-cloud strategies for disaster recovery and vendor lock-in reduction.
Conclusion
Building resilient distributed systems at scale requires careful consideration of architectural choices, trade-offs, and a keen awareness of performance implications. The lessons learned from our scaling journey can serve as a guide for others undertaking similar challenges.
Actionable Recommendations
- Regularly revisit your sharding strategies as user patterns change.
- Implement multi-tier caching to improve response times significantly.
- Adopt a Zero Trust security model to safeguard your services.
- Monitor and adjust consistency models based on use cases.
By sharing experiences and insights, we can collectively raise the bar for system architecture and design in the tech industry.
Want This Built for Your Team?
I help companies in the US and Canada ship production AI systems, either directly or as a white-label delivery partner.
Views: 0