Question
Performance implications of offset pagination in moleculer-db
Ira Lane
0 reputation · 17 Jun 2022, 14:26 UTC
146.8K views0
When using the moleculer-db package, the standard find action supports
limit and offset parameters to paginate results. While the parameter validator can enforce a maximum page size to prevent oversized requests, the underlying database execution behavior varies significantly based on the offset value.In many adapters, such as SQL-based or MongoDB, a high offset requires the database to scan and discard numerous rows before returning the requested set. This can lead to linear latency growth as users navigate deep pages. While keyset pagination offers a more scalable alternative, it requires a unique indexed sort key and custom cursor handling beyond the basic find action parameters.
How does moleculer-db handle the performance cost of deep-offset queries across different adapters? Is there a recommended pattern for transitioning from offset-based to keyset-based pagination without bypassing the built-in find action logic?