Skip to main content

edge-network

app_form_response#create & Next.js / Prisma / PlanetScale stack

The general idea behind the implementation of above technology stack at POWr is to make infrastructure more scalable. The GKE cluster allows to scale up containers but can't resolve our bottlenecks.

The RDS Postgres database is our first problem. The connection pool is limited and can't be extended significantly. We get a delay as soon as the database connections are exhausted. The solution of the problem is PlanetScale database. It provides 10000 connections even for starting Scaler pricing plan. According to the vendor they also take care about vacuuming, rebalancing and so on. PlanetScale uses Vitess under the hood. Vitess is used for MySQL scaling by the biggest tech companies in the world. Moving the biggest tables from RDS to PlanetScale allows us to reduce pressure on the Postgress database.

Our second problem is the Rails framework. It uses a lot of our server resources for heavy loaded endpoints. E.g. POWr servers start crying when we get too many form responses at app_form_response#create. The solution of the problem is Next.js API hosted on Vercel Edge Network. The Vercel Edge Network is like a CDN for API. It should help us to process more requests with no delays and reduce the load on the Rails server at the same time.

The most heavy loaded endpoint which can't be cached at the moment is app_form_response#create. This endpoint and subsequent Sidekiq workers interact with many Postgress tables. The biggest tables are app_form_responses and pending_transaction which should be moved to PlanetScale as a first step.

The technical implementation of this migration to PlanetScale requires powr project to have 2 simultaneous database connections to Postgress and PlanetScale at the same time. Our current Rails version doesn't support this with ActiveRecord. And as soon as the ActiveRecord is not the most performant in terms of server resources consumption, we gonna use gem Sequel for PlanetScale connection. According to benchmarks Sequel has much better performance.