TopN for your Postgres database
citusdata.com
citusdata.com
We heavily rely on this to power our analytics API. We use it precompute tops for billions of daily events. We can then fetch tops across specific time range usually in the order of the milliseconds on the fly. This was a game changer for us :)
Postgresql and most mature database systems already have topN/offset/paging solutions.
Also, what's the point of aggregating JSONB data? If you need to calculate topN, why not normalize the data properly and index the data? Then top N will be blazing fast without needing an extension?
If the data set is extremely large then you can maintain an internal "Top N" table that gets calculated when data is added/removed. It all depends on the workload, but inserts/updates/deletions may be slightly slower, but reads of topN will be constant speed.