#Ecommerce microservice using NestJs
14 messages · Page 1 of 1 (latest)
Few weeks ago we released a rewrite of an existing ecommerce website in Next for front-end and Nest for backend (graphql). No microservice was necessary, it's doing just fine as a single monolith.
I can recommend https://typesense.org/ for fulltext search, filtering, faceting etc. functionality. Their managed cloud offering is not that expensive (you can also self-host), it's fairly easy to implement and saves tons of headaches building the usual listing page.
I'm not too happy with chosen ORM (Prisma) since it makes it difficult to optimise some frequently ran queries while maintaining type safety. I'm considering adding Kysely as a companion to Prisma. I'd experiment with MikroORM if I was starting from scratch today. You can check this post for some stories: https://discord.com/channels/520622812742811698/1096846405257138226
With daily request count over 250k the api server is running happily on 1vcpu 1gb ram instance with average cpu usage less than 10%, memory ~25%.
CloudFlare R2 for file storage, Image Resizing API so I don't have to pre-process product images myself, simple worker script for protecting staging environment access.
For auth solution we went with Firebase, for the generous free plan. If we planned for less users, we'd probably go Auth0 which offers a bit more control. AWS Cognito also looked fine.
Happy to answer any specific questions 😉
Consider using https://www.vendure.io/
Build limitless solutions - from eCommerce to multi-vendor marketplaces and beyond. Cater to any audience - B2B, B2C, D2C, P2P, or X2X.
It's based on NestJS
How are able to combine NextJs with NestJs in a single repo/project? As I am actually thinking of that combo as well.
But I think in my case I need to make NestJs as a microservice as there wipp be APIs that will be used by another project so there will be multiple NextJs projects that will be using the NestJs APIs. Would that work?
Sorry for the multiple replies, as I am still collecting my thoughts on this one.
Anyway, where did you host your database? I am planning to use Postgresql via Cloud SQL. Will that suffice?
Thank you for your response. It is a huge help.
Thank you. Will consider this.
Next lives in a different repository, it communicates with the backend over graphql. We actually already have 2 apps consuming the API - storefront and admin app.
You don't need to make NestJS as a microservice, you probably want Nest backend as a full-size standalone application, providing some kind of API to any number of clients (next apps).
We're hosting both app and postgres database in https://northflank.com/, but CloudSQL would definitely work too.
Thank you @wanton hearth . Another question though about NextJs, as this is my first time deploying anything by myself, I'm so sorry if I have many questions. NextJs is a full-stack framework right? So how where you able to deploy it without the backend, did you just deploy the result of next build? Thank you.
I wouldn't call NextJS full-stack. It has capabilities for running code on the server side, but it's not suitable for complex backend apps such as e-commerce. They try to tighten the gap, but mostly on the Vercel-side, not framework-side. Cronjobs, background workers for stuff like order/payment status synchronization, IoC container, I don't know what else.
We found it suitable for data fetching - at the NextJS backend, we fetch product details from the NestJS backend. Nest side has the business logic - how much the product costs, knows how to apply percentual discounts, can calculate VAT, margins, etc.. Next just receives all this data and makes sure to pass it the right way, render correctly so search engine crawlers can index the site with no troubles, finds a page to redirect to if the product is no-longer available, etc..
So, we use the Next api routes and SSR, we run it on Vercel for now, but it doesn't contain any critical business logic. All that is handled at NestJS backend.
Just to clarify, you mean NextJs cannot do cronjobs, background workers and etc?
It could, it's just not built into it. You can do crons with Next with Vercel: https://vercel.com/blog/cron-jobs. If you decide to deploy elsewhere, you have to do it differently (depending on the provider). Also Vercel limits you to 10/60s execution time. Longer cron would have to be achieved in a different way.
Long-running background workers, message queues and stuff, are another topic just for itself. In the end, Next is just another Node framework, so you could theoretically achieve anything you can with Nest. It's just not built for that purpose, and thus it will be worse developer/operations experience than solving the same in backend-first (that's a bit misleading claim, but you get the point) framework like NestJS.
At least that's how I see it. Next as a front-end framework capable of simple backend tasks. Similarly, Nest as a back-end framework capable of doing front-end stuff (it could render react app, it's just not really built for it; you have MVC with Handlebars, that's front-end, right?).