DEV Community

Marceli-Wac
Marceli-Wac

Posted on

What technology would be suitable for region-based, serverless backend solution on AWS?

I am currently planning the development of the backend for my personal website. In short, the front-end is written in React and at the current stage is essentially ready to consume backend. It is hosted on AWS using the S3 bucket set up for website hosting and exposed using CloudFront distribution. This means that the access to the website itself is cheap in terms of latency, regardless of the location, as the results of querying that website are stored in CloudFront's cache.

Now, I'm planning on providing the content for that website using some sort of serverless-enabled document database (considering MongoDB with Atlas and DynamoDB with Global Tables). My only worry is that at the moment, not many of these solutions provide an out-of-the-box region-based routing that optimises the location from which resources are served. MongoDB Atlas has some nice VPC-peering options which integrate really well with AWS, but seem to lack any region replication; DynamoDB on the other hand has global tables which does exactly that, but does not expose a single endpoint which would route requests to the closest database (or at least I could not find a way to set it up like so). One thing that I could think of is to setup the manual routing to the databases via Lambda@Edge, which would be both serverless and region-based, but that sounds like a lot of hassle and manual setup to find the best database server and just seems flaky.

Another way is to use a static site generator, or perhaps even a script that would compile a JSON from the database with website. Together with DynamoDB streams (or any other db hooks) this could allow me to deploy new version of my website with updated data. Considering features like comments etc. this obviously seems inefficient as the website would have to be re-deployed with every change to the database and that takes few minutes.

Finally, I'm wondering whether exposing a single database endpoint in just one region via Lambda@Edge and using it as part of the CloudFront distribution viewer request would be a viable solution for my use case.

Overall, the setup is a bit overkill for the traffic I am expecting and I don't suppose that a second of delay for someone on the other half of the world will make a difference. Then again, we live in the world where all of that server(less) infrastructure is essentially free, so why not go for it and learn something in the process.

Any answers, opinions or questions are very welcome!

Top comments (0)