Multi-Tier Web Application with Cross-Region Latency
A company runs a three-tier web application in Alibaba Cloud. The web tier consists of 12 ECS instances behind an SLB, the application tier has 8 ECS instances, and the database tier uses ApsaraDB for RDS (MySQL) with a read replica. All resources are in the China (Hangzhou) region. Users are primarily in Singapore and report response times of 2-3 seconds for API calls that should complete in 200ms. The application tier makes synchronous calls to the database for each request. Monitoring shows that the database CPU is at 80% during peak hours, and the application servers have 60% CPU utilization. The SLB is configured with round-robin and health checks every 5 seconds. The company wants to reduce latency to under 500ms for Singapore users while maintaining data consistency.
1. What is the most likely primary cause of the high latency for Singapore users, and what architectural changes would you recommend to address it?
Read the worked answer
The primary cause is the round-trip time (RTT) between Singapore and Hangzhou, which is typically 50-100ms per request. With multiple synchronous database calls per request, latency accumulates. Additionally, the database CPU at 80% indicates potential queuing delays. To reduce latency, deploy the web and application tiers in the Singapore region, and use a read replica of the RDS instance in Singapore for read-heavy operations. For writes, implement a write-through cache or use a message queue to asynchronously replicate writes to the primary database in Hangzhou. Alternatively, use Alibaba Cloud's Global Accelerator to optimize the network path, but this may not be sufficient to meet the 500ms target. Also, consider increasing the database instance size or optimizing queries to reduce CPU load.
2. If the company decides to keep all resources in Hangzhou but use Alibaba Cloud's Global Accelerator, what factors should they consider to ensure it meets the latency requirement?
Read the worked answer
Global Accelerator can reduce latency by optimizing the network path, but it cannot eliminate the speed-of-light limitations. The company should measure the actual RTT between Singapore and Hangzhou with and without Global Accelerator. They should also consider the number of round trips per request: if each request involves multiple database calls, the cumulative latency may still exceed 500ms. They should optimize the application to reduce the number of synchronous calls, use connection pooling, and implement caching. Additionally, they should monitor the database CPU and consider scaling up or adding read replicas to reduce query latency. A pilot test with real users is recommended to validate the improvement.