'How to maintain the application in AWS across regions

I have an EC2 instance created in one region for the deployment, and I would like to maintain the same application in another region to reduce the latency with the ability to deploy locally at a region and have the database in sync across regions.

The repositories inside the application are docker container images managed in ECR on AWS including the mongoDB database image which I want to use it in multiple regions.

For example, the customer in region A make a change in the application, and the customer in region B should be able to see the change and all data as the customer in region A can see.

Are there any possible ways to achieve the multi-region deployment for this case?



Solution 1:[1]

This would require the combination of several technologies.

  1. We can start with DNS configured with latency-based routing policy. This will enable your customers to get redirected to the ALB that can respond faster in their location. (Nearest by physical distance not necessarily mean faster because of sea-based cables! Yes sea cables causes fewer network hops).
  2. Consider using an auto-scaling group that will allow you to spread copies of the application running on EC2 into multiple availability zones of the region. You might want to consider deploying this Auto-scaling group across multiple regions that the organization have to serve.
  3. That will need a load balancer per region too! This will allow you to distribute the traffic between multiple worker nodes / EC2s in a single region.

The same thing could be achieved by using different scalable compute technologies like EKS, ECS, EB, Lambdas but at the end of the day, its the DNS that will have to stay the same to achieve lower latencies.

If you find this difficult to implement, using CloudFront not only allows you to cache your static content but it also gives you the following benefits when integrated with a load-balancer!

  • Having CF in your architecture allows customers to get routed the nearest local Points of presence (pops)
  • From the pop, the requests then traverses the AWS private global network which allows them to get routed faster from the customer region to the origin region where the ALB resides because of lesser traffic flowing through this dedicated network (This of it as an express way).
  • It also increases the tolerance of your application to handle higher network traffic because of these POPs serving like an umbrella protection (Although you're getting another problem called denial of wallet attacks instead of DDOSes).
  • Oh by the way, Serving traffic within AWS private global network is also cheaper than having customers directly hitting ALBs by around ($ 0.005 per GB)
  • CF also allows us to embed L7 (WAF) & L4 (Shield Basic & Advanced) protections.
  • CF also allows us to create origin groups which helps in making sure that if there's a regional outage, we can redirect the traffic into a failover origin that resides on another region through the use of origin groups

Solution 2:[2]

I see your concern is in syncing data. Then the only way is to replicate data cross regions. But it is a trade off.

If you maintain data centrally, access latency is impacted as you pointed out. But syncing data across region also has latency. If the app is read intensive, it is worth to cross regionally sync the db. If it is write intensive, i think central database is better.

Anyway since you are using MongoDb on EC2, have to look at the product capabilities, if MongoDB supports syncing across two instances.

As for AWS, they do have DynamoDB global tables that is meant to handle just what you asked for.

But like I said just because it is possible does not mean you have to do it. Consider the pros and cons of both options.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2