Devographics / Monorepo

Monorepo containing the State of JS apps
surveyform-sigma.vercel.app
Other
125 stars 50 forks source link

Various small DX improvements #217

Open SachaG opened 1 year ago

SachaG commented 1 year ago

As I'm working on the codebase, a couple notes of stuff we could improve to discuss later.

eric-burel commented 1 year ago

Quick feedback:

During build, performances are not a big deal, however I cannot yet load everything statically during build because Next doesn't support static layout (eg loading the survey definition) mixed with dynamic pages (eg loading the user response for the survey).

So, on some pages we may end up loading the survey on every request. I am not fond of using GraphQL because it's slower, and we do not benefit from GraphQL in this use case, since we have roughly 3 types of query (getting the survey definition, getting the question, and getting the list of surveys) that barely ever change. Calling Redis seems more efficient and simpler to me. I also use a bit of short-lived in-memory caching (eg a few minutes) to reduce the workload, since all users will load the same survey definitions there is no need to reload on each request.

I am not yet sure if we want to put this logic in API, maybe just in shared code instead? I think the API is more relevant for the result app which is highly dynamic than the surveyform we is simpler and can be optimized a bit more "aggressively" and thus need to stay independant.

SachaG commented 1 year ago

So, on some pages we may end up loading the survey on every request. I am not fond of using GraphQL because it's slower, and we do not benefit from GraphQL in this use case, since we have roughly 3 types of query (getting the survey definition, getting the question, and getting the list of surveys) that barely ever change. Calling Redis seems more efficient and simpler to me.

Yes I agree, I just meant we should consider the API as the source of truth, but we can access a cached copy of its data, that's fine.

I also use a bit of short-lived in-memory caching (eg a few minutes) to reduce the workload, since all users will load the same survey definitions there is no need to reload on each request.

If that's possible then yes I think in-memory caching (nodeCache or similar) is the best solution. But I thought it wouldn't work for surveyform because of the serverless architecture?

eric-burel commented 1 year ago

For the serverless architecture, that's a very good question and I was surprised by the answer:

You still have to make the code serverless-friendly, for instance each page should connect to the database independently from the others, because you can't tell which is requested first or which will actually get bundled. But in the end you will not have that many instances so caching works ok.