DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • Deploy an ASP.NET Core Application in the IBM Cloud Code Engine
  • Auto-Scaling a Spring Boot Native App With Nomad
  • How Java Apps Litter Beyond the Heap

Trending

  • Monoliths, REST, and Spring Boot Sidecars: A Real Modernization Playbook
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • Navigating Change Management: A Guide for Engineers
  • How to Introduce a New API Quickly Using Micronaut
  1. DZone
  2. Data Engineering
  3. Databases
  4. Lessons Learned Moving From On-Prem to Cloud Native

Lessons Learned Moving From On-Prem to Cloud Native

See how to move a sample ecommerce app from an on-premise architecture to a cloud-native one, using YugabyteDB database, Hasura Cloud, and Vercel.

By 
Denis Magda user avatar
Denis Magda
DZone Core CORE ·
Updated Nov. 16, 22 · Opinion
Likes (4)
Comment
Save
Tweet
Share
3.6K Views

Join the DZone community and get the full member experience.

Join For Free

Recently, I came across a sample e-commerce application that demonstrates how to use Next.js, GraphQL engine, Postgres, and a few other frameworks to build a modern web application. The application supports basic e-commerce capabilities such as product inventory and order management, recommendation system, and checkout function. This made me curious as to how much effort it would take to turn this application from an on-prem to a cloud-native solution.

The original architecture for this sample app looked like the below diagram. You can start the whole setup in a few minutes following this guide.

Original architecture for sample app

My curiosity was so tempting that I forked the project and replaced several components from the original architecture with their cloud-native counterparts:

Original architecture with replacements of several components with cloud-native counterparts

  1. PostgreSQL to Yugabyte Cloud. 
  2. Hasura on-prem GraphQL engine to Hasura Cloud. 
  3. Local server for the Next.js frontend and backend to Vercel.

The migration didn’t finish overnight but was relatively smooth. Let’s quickly walk through my three main lessons learned.

Lesson 1: PostgreSQL Compatibility Matters a Lot

In a cloud-native deployment, I want to have a relational database that scales horizontally and is resilient to failures such as zone- or region-level outages. Even though YugabyteDB is a Postgres-compliant, distributed SQL database, I was still skeptical that the application's migration would go smoothly with no code changes on the SQL side. My skepticism grew even more after seeing that the original DDL script had many stored procedures and triggers that are pretty hard to support in many distributed databases.

However, my skepticism turned into joy when the application booted with no issues after I introduced two changes to the Docker compose startup script:

  1. Asked Docker to launch a YugabyteDB container (comprised of YB-Master and YB-TServer) instead of the Postgres one. 
  2. Updated the database URL in the GraphQL engine container’s settings to the following:

postgresql://yugabyte:yugabyte@yb-tserver:5433/yugabyte

And that’s it! That's Postgres compatibility in action. The application was running, the data was loaded, and the frontend worked with no issues. So, I prepared a separate docker-compose file for those who would like to launch the app on-premises with YugabyteDB. I also moved closer to my original goal — turning the app into a cloud-native solution.

Lesson 2: Cloud-Native Services Are Easy to Switch To

This lesson might be just an obvious fact to most of you. But for me, a person who developed his first application when nobody even talked about cloud environments—and IT/database administrators were on every serious dev team—this was a big positive lesson.

To remind you, I intended to transform the application to a cloud-native solution by replacing the following components with their cloud-native counterparts:

  1. PostgreSQL/YugabyteDB to Yugabyte Cloud. 
  2. Hasura on-prem GraphQL engine to Hasura Cloud.
  3. Local server for the Next.js frontend and backend to Vercel.

So, starting with step 1, I provisioned a 3-node cluster with Yugabyte Cloud. The cluster is deployed across several availability zones and can tolerate zone-level outages:

Cluster deployed across several availability zones

Next, moving to step 2, I created a Hasura Cloud deployment using the Standard Tier (that scales automatically and supports high availability) and connected Hasura to my Yugabyte Cloud database:

Connect Hasura to Yugabyte Cloud database

Lastly, finishing with step 3, I deployed the Next.js backend and frontend with Vercel as instructed through the Environment Variables settings to connect to my Hasura Cloud GraphQL engine:

Deploy Next.js backend and frontend with Vercel to connect to Hasura Cloud GraphQL engine

That’s it! As a result, my e-commerce application was running on a cloud-native stack, and the switch to these services was an easy thing:

Cloud-native stack

Lesson 3: Zero Code Changes Are a Myth

As you see, the migration was smooth, and most of my time was spent adjusting configuration settings and provisioning cloud-native services. But I cannot say this was a “zero-code-changes” type of experience. Personally, I think that that’s just a myth. You still have to be ready to tweak your code to make it work properly or much more efficiently with new software or services.

In my case, I had to change the Next.js logic in a few places, making sure Hasura Cloud’s admin secret is used correctly by the GraphQL clients. I also had to optimize the SQL scripts the app used for initial data loading. For instance, the original SQL script loaded 85,000 products by executing 85,000 individual INSERT statements that translated to 85,000 distributed transactions in YugabyteDB! But that’s just an anti-pattern for distributed databases. Therefore, I dramatically reduced the initial loading time by replacing those 85,000 individual INSERTs/transactions with ~17 INSERTs/transactions with 5,000 values each.

Conclusion

Instead of closing the article with some clever statements and high-level guidance, I would encourage you to experience the process from start to finish yourself (except for the code-level changes, that’s done for you!):

  • Deploy the app with the initial architecture (Postgres as a database) on your laptop.
  • Transition to YugabyteDB but still deploy locally on your laptop. Follow the same instructions as above but ask Docker to start YugabyteDB.
  • Deploy the application in a cloud-native environment.

If you follow these steps, then the application UI will look as follows:

Application UI


Cloud application Docker (software) Relational database app YugabyteDB GraphQL PostgreSQL Next.js Engine

Opinions expressed by DZone contributors are their own.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • Deploy an ASP.NET Core Application in the IBM Cloud Code Engine
  • Auto-Scaling a Spring Boot Native App With Nomad
  • How Java Apps Litter Beyond the Heap

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!