logo
post image

Experiences of Migrating PHP-MySQL Site to NodeJS / React on AWS Cloud

It's been around 3 years since the last post on usefulangle.com. Well, I'm not proud of it, but I was insanely busy in a contract project (I do freelance for a living).

However some good news is that UsefulAngle is now upgraded to a new technology — probably the latest in web dev. Previously it was a PHP-MySQL based site.

Upgraded Technology

Currently UsefulAngle is using Next.JS, the popular React framework. The database being used is DynamoDB, the NoSQL database from AWS.

Frankly speaking I chose DynamoDB because it would be free for the number of API requests the site would be making. With Next.JS, all pages are built as HTML and cached. My strategy was to refresh the cache only in 12-24 hours. This helped in reducing the site's DynamoDB API requests and getting me almost a free bill for database usage.

If I had gone for Relational Database Systems such as MySQL on the cloud, the database costs would have been around $18 a month (taxes included).

The Next.JS app is running on a AWS EC2 server (well technically I'm using AWS Lightsail service, but Lightsail is nothing but a simple UI for connecting related AWS services required for a modern site). The server utilizes 2 vCPUs and 1 GB of RAM. It costs around $8-9 a month (taxes included).

The server is connected to a Cloudfront distribution, which is basically a CDN service from AWS. Costs around $3 a month for my site's usage bandwidth.

My reason for choosing Cloudfront was also cost cutting. If I'm using Cloudfront, the site gets the advantage of a CDN, plus a free SSL certificate from AWS. Otherwise I needed to purchase a SSL certificate too. Yes there are services such as Let's Encrypt proving free SSL, however periodic adjustments are required.

Franky speaking it becomes overwhelming to work with so many cloud services to create even a simple site such as a blog — I did not want to take yet another service for a SSL certificate. I got tired and decided to stick to only one service provider, AWS.

The Cloudfront CDN is finally connected to the domain, and this is how the current version of usefulangle.com comes up!

Experience with Next.JS

Next.JS was a good experience. The build process was a bit new for me, and an extra step towards creating a site. However the build process creates HTML for all pages and they are cached. So something good is happening, hence bearable.

Easy routing was one of the good things about Next.JS. Incremental Static Regeneration (ISR), which basically re-fetches new content at given intervals was such an awesome feature.

One shocking thing about Next.JS though was its low score in speed test and web vitals!

While writing code I was damn sure that since I was using Next.JS, the site would have an amazing score in speed test and web vitals. However at launch the score was a mere 34!

Pretty shocking. Turns out Next.JS is not the best for speed tests and web vitals. That is understandable actually - so much of chunked JS and CSS are generated.

I managed to improve the score to 80-85 using some techniques. However the older site which was custom made and was pretty lightweight had better speed score. However I had no option at that point. 80-85 score was also good enough. All metrics were actually good except Total Blocking Time.

Experience with DynamoDB

Like I told earlier, I chose DynamoDB to cut costs. It is actually quite cheap than other database options.

Learning about a new database system was also a good experience. Their tables indexes are an amazing feature and is indeed very fast like they advertise.

Since it was NoSQL, a single table design is the first recommendation. However creating a single table for everything and working on it is a pain. Too much of duplicate data. I did not want to pursue that. I created separate tables like the one in the older MySQL database (DynamoDB tables have no foreign keys).

Experience with AWS

Nice experience overall. Impressed with Lightsail that provides a very simple UI for connecting various services (servers, cdn, load balancer, domain).

They are being costly with time though. I remember a basic server used to cost $3.5 per month. Now the minimum price is $5 a month. Almost a 50% increase.

However still cheaper than the older options. I used to pay GoDaddy $50 a month for a pretty average server. Now my current cost would not exceed $10 I think, with a better performance.

Modern Day Web Development

I have been creating sites since long, and I must say web development has gone complicated. Its not only about code now. Code + Cloud makes creating even a simple site not so easy.

I was overwhelmed — many things to manage. I can now understand why modern IT teams have some DevOps people too.

However once you understand setting up the cloud, things become okayish.

Conclusion

So that was all about it. I'm eagerly looking to write more content on the new site!