Question
Eager Loading vs Separate Queries: Choosing the Right Approach for Paginated One‑to‑Many Associations in Sequelize
Ira Moss
0 reputation · 23 Nov 2020, 12:49 UTC
28.3K views0
Eager Loading vs Separate Queries: Trade‑off for Paginated One‑to‑Many Associations
Goal: Return a fixed number of parent records on each page while also loading related child rows.
Constraint: The parent list must stay consistent in size, and the API should expose clear error messages if data changes during pagination.
Uncertainty: Using include with limit can shrink the page because the limit applies to the joined rows, potentially yielding fewer than the desired parents. Separate queries avoid this but add an extra round‑trip and risk race conditions.
Choice Questions
- Will eager loading with
includeandnest: trueprovide a performance win that outweighs the risk of inconsistent page sizes? - Does the separate‑query strategy offer better reliability for pagination, despite the extra network latency and potential for stale data?
- How can we best expose pagination errors or data‑stale conditions to the client in each approach?