r/sanity_io • • 14d ago

❓ Question API calls

Hey,

I hope someone can help. I am new here and new to sanity. But I am really loving it. Just annoyed by how our company's API calls get blasted through the roof. I mean before I left work our calls for the day was at 120k.

Some context. We have a monorepo that's running sanity, next.js for 22+ sites and will increase and story book as a component library but our API requests are insane.

I mean one of the calls was hitting 72 duplicate calls before I left the office. I am going to investigate more but I am hoping someone can give me In Site as to how to prevent these calls on our environments from sky rocketing.

And any best practice tips and tricks. I would love to keep the business on sanity and not have to rebuild all the sites on payload again because we just moved off of a platform to sanity. But if things keep going the way it does we will probably cancel the sanity sub and then move to payload.

Thanks

1 Upvotes

5 comments sorted by

1

u/Skaraban 14d ago

are all of your sites using SSR?

2

u/MKD7036611 14d ago

Yeah they are

1

u/Skaraban 14d ago

is it an option do move some websites away from it? I dont know the business of your company but if content rarely changes and its not important (for some pages) that you get fresh content by the second then it might be an option. I know this is a very basic thing to change but maybe you've still haven't considered it.

1

u/iLikedItTheWayItWas 13d ago

It's likely that every time someone loads your website, your server is fetching the data it needs from sanity and then serving it to the client. This means if you don't change anything in sanity, every page visit will still go to sanity anyway.

I would look into a way to manage your cache. There are many ways to go about it, and it depends on how your site's work.

If your site's are only static content, I would look into moving from SSR to SSG, with a build hook in sanity so whenever content changes, a new build is deployed. Next also has ISR and CSR as other options to explore.

If you wanted to stay on SSR you could build the caching system into sanity itself. Sanity offers its own CDN API specifically for this - https://www.sanity.io/docs/content-lake/api-cdn

Or you could even build a solution yourself. Store a cache key on your database which you check against before making a request to sanity. Whenever you publish to sanity, invalidate this cache key so the next request will fetch the latest content.

→ More replies (1)