Not the database? That's odd. I would think that serving those requests would just involve fetching from the database and reformatting everything into ActivityPub, with the database doing the heavy lifting.
I say this because, in a recent project of mine, that's how it went: the application itself did everything basically instantly, but the database had to do a lot of work for each request.
My project was non-HTTP and write-heavy, though, unlike Mastodon, so 🤷♂️.