Hi all!
We have a NextJs application that queries strapi for data. The website will have around 50 milion hits per year. We rewrote the controllers we have and managed to speed up the request response time significantly.
Now we wonder whether we can bypass Strapi and somehow use its query engine in the NextJs application. Basically we want to bypass the middleman which should speed up the response time quite much.
Is there any way we can use any of strapi’s magic in an outside application and if not possible what is the other approach that we can take? I suppose that we can query the database directly from an api ednpoint in NextJs but how would field population and such work then?
Thanks in adcance.
This is not posible you can do 2 things 1 cache responses in strapi so it does not have to make the querys
second thing is if the strapi instance where to get overloaded you could have multiple strapi instances with a balancer before them to incease the workload strapi can handle
Hi @Ivan_Shoshkov, It’s great that you’ve been able to optimize your Strapi controllers and improve response times. If you’re considering bypassing Strapi to query the database directly from your Next.js application, there are a few things to consider.
Strapi provides a REST API and GraphQL API that you can use to fetch data from your Strapi application. If you bypass Strapi and query the database directly, you’ll need to handle several things yourself, such as data validation, access control, and potentially more complex queries.
However, if you still want to leverage Strapi’s query engine without going through the REST or GraphQL APIs, you might need to consider a few options:
- Direct Database Queries: You can connect to your database directly from your Next.js application. This would involve setting up a database connection in your Next.js app and writing raw SQL queries or using an ORM (Object-Relational Mapping) library to interact with the database. This gives you more control but requires you to handle many aspects that Strapi might handle for you.
- Use Strapi’s REST or GraphQL API: Instead of bypassing Strapi, you can continue to use its APIs but optimize the queries you make. Make sure you’re using the appropriate endpoints and query parameters to fetch only the data you need. Strapi’s APIs provide a level of abstraction and can handle things like access control and data validation.
- Caching: Implement caching strategies to reduce the load on your database and improve response times. You can cache the results of frequent queries to avoid hitting the database repeatedly.
- Microservices: If performance is a significant concern, you might want to consider a microservices architecture. In this scenario, you could have separate services for your Next.js frontend and your backend (Strapi). This allows each service to scale independently, and you can optimize them separately.
Remember that bypassing Strapi means you’ll need to take on more responsibilities related to data management and security. If you decide to go this route, ensure you thoroughly test and secure your direct database queries to prevent potential vulnerabilities.
Thank you both for the replies, I apprecieate it! Probably will proceed with caching and load balancing 