Video glosses over the critical distinction: while the offset is a relative number from the start of all records, the cursor is a direct memory/storage pointer to the exact record where we left off, which is always faster. (The video mentions "pointer" only in passing.)
But if we index the table on the column we order by, it should not take more than logN to reach the offset right? N being the number of records in the table.
Great videos. I think there is a minor error in the SQL statement around 8:11. It should either be: SELECT * FROM products WHERE created_timestamp > 12345678 ORDER BY created_timestamp LIMIT 50; or if you are working backwards in time SELECT * FROM products WHERE created_timestamp < 12345678 ORDER BY created_timestamp DESC LIMIT 50; The query in the video will just return the first 50 records (or less if there are less than 50 records with created_timestamp < 12345678) of the data set, it will not do pagination. The critical part is to get the comparison operator () and the ordering (ASC, DESC) correct. The default ordering is ASC, so there is no need to specify that. The URL above the query is also confusing. This is more the matter of style than correctness. The cursor that is being passed in as a parameter is the startCursor, not the nextCursor. The next cursor returned by one query becomes the start cursor of the next query. This may actually be one of the reasons that the SQL statements is incorrect.
This is common interview question as well and you give a very good explanation, it clears my doubts and I understood the concept. Thank you for making this video. Keep it up.👍
I just faced the pagination problem in production :-(). When you have nobody around to ask, then you search and rewrite your code again and again. I searched for days how to deal with that, thanks you so much, i 'am going to rewrite my code !
Thanks 🙂 Good question about the back button. There are several ways this can be implemented, but as long as you have the cursor you can decide to read records ahead of it or behind it.
Usually if you have more than a few thousand records, you might want to start thinking about pagination. It’s difficult to state an exact number because it depends on each situation. Hope this helps!
Great vide, can we not have a hybrid approach where both are used consistently? Users wan to jump to the last page just to see the last updated content, so off set pagination is useful here, however from there they might wanna go back to previous pages one by one which they can do by cursor based pagination. This might be too complex and unnecessary but would be amazing.
In cursor-based it is mentioned to have the data to be sequential , e.g. through index. How cursor-based helps in case of query is associated with some sort or filter on the resultset? Indexing will be complex in that case I believe. Great simplicity & clarity in the contents though👏.
Thanks Rano! :) These concepts are foundational and often need to be integrated with your database of choice. So it really depends on each use case and performance requirements.
Thanks for the clean explaination. Quick question on how to go back ? nextCursor would give the next page, but when they want previous page how to go back ? should we change the query ?
@@ambientcoder5462 If we want to go back like 3 pages, then how do we implement that ? I can only keep tracke of current page when I move next page & after i click back i can go one page backwards but if I want to move to move back 3 - n pages how do i do it ? any help appreciated :)
Good video. Although i dont think the example given for cursor based one is the best one. It uses order by which in itself is not the best way. Using rowid as a cursor will be much better in terms of performance. Although that might now be the best thing for security.
Doesn't data base use an instant access ? Why does data base need to pass the all way from 0 to N every time? Do you know how an array works? I think data base work like that.
This is wrong. You don’t know what you are talking about. First, you offset optional query was wrong. It is missing order by clause. You need to order by unique key to have readable offset. Your so called cursor pagination is wrong also. In your example you are getting 50 records. But, your predicate might have let say 200 records with that cursor. How you are going to get next 150? . Even in this case you need to build chunks of offsets.
Video glosses over the critical distinction: while the offset is a relative number from the start of all records, the cursor is a direct memory/storage pointer to the exact record where we left off, which is always faster. (The video mentions "pointer" only in passing.)
But if we index the table on the column we order by, it should not take more than logN to reach the offset right? N being the number of records in the table.
omg, the 3-hour lecture from my prof is well explained in 11 minutes. Thanks a ton!
Thank you! I’m glad you found it useful 🙂
I guess your prof doesn't really understand it then.
Great videos.
I think there is a minor error in the SQL statement around 8:11.
It should either be:
SELECT * FROM products
WHERE created_timestamp > 12345678
ORDER BY created_timestamp
LIMIT 50;
or if you are working backwards in time
SELECT * FROM products
WHERE created_timestamp < 12345678
ORDER BY created_timestamp DESC
LIMIT 50;
The query in the video will just return the first 50 records (or less if there are less than 50 records with created_timestamp < 12345678) of the data set, it will not do pagination.
The critical part is to get the comparison operator () and the ordering (ASC, DESC) correct. The default ordering is ASC, so there is no need to specify that.
The URL above the query is also confusing. This is more the matter of style than correctness. The cursor that is being passed in as a parameter is the startCursor, not the nextCursor. The next cursor returned by one query becomes the start cursor of the next query. This may actually be one of the reasons that the SQL statements is incorrect.
Wow man! Thank you so much for this explanation. It was easy to understand and the animations used makes things even better!
Very well explained and in a concise manner. Thanks 🙏
Thank you so much, recently got into the backend and was confused about the pagination, thank you so much
Great to hear that you found this helpful! 🙂
This is common interview question as well and you give a very good explanation, it clears my doubts and I understood the concept. Thank you for making this video. Keep it up.👍
Thanks a lot! I’m glad it helped clear your doubts! 🙂
Thank you, this is so helpful! Please continue this series!
A really well made and explained video! Thank you for sharing!
Glad it was helpful!
Very concise and clear explanation . Thanks for you contribution !
Thank you Stefan 🙂
Really clear explanation, thank you!
Glad to know you liked it 🙂
Great explanation, thank you!
OMG you should get more views, Thanks for explaining it so well and precisely :+1:
Glad you liked the explanation and thanks 🙂
amazing desmonstration
Excellent content!
Thanks a lot 🙂
Thanks so much explained so well
excellent video!
Thank you so much!
Thank you 🙂
Thanks a lot on this from a Junior Dev :D
Happy to help!
For cursor based - Records need to be added sequentially to DB only if we'd like to have consistent results
Thank you! So well explained!
Well done! Best explaination I found on topic. Made all clear. Waiting for coding version:-).
I just faced the pagination problem in production :-(). When you have nobody around to ask, then you search and rewrite your code again and again. I searched for days how to deal with that, thanks you so much, i 'am going to rewrite my code !
awesome explanation
Thanks! 🙂
veeeery helpful!! thank you!!
Hi wonderful explanation, but what about the back button request 8:51
Thanks 🙂
Good question about the back button. There are several ways this can be implemented, but as long as you have the cursor you can decide to read records ahead of it or behind it.
@@ambientcoder5462 Thank you for your reply, I think this works as per stripe's API, ?limit=10&ending_before="first response's ID"
this video is exccelent!
I’m happy to hear that. Thanks!
that was great! thanks
Thanks 🙂
thanks for explaintion
wonderful explanation
Thanks! Glad you liked it :)
I did enjoy watchin all your videos. I miss information at least about rough estimate what means big data set etc.
Usually if you have more than a few thousand records, you might want to start thinking about pagination. It’s difficult to state an exact number because it depends on each situation. Hope this helps!
Great vide, can we not have a hybrid approach where both are used consistently? Users wan to jump to the last page just to see the last updated content, so off set pagination is useful here, however from there they might wanna go back to previous pages one by one which they can do by cursor based pagination. This might be too complex and unnecessary but would be amazing.
I'm putting this comment here because I enjoyed this video on API Pagination
Glad to hear it!
In cursor-based it is mentioned to have the data to be sequential , e.g. through index. How cursor-based helps in case of query is associated with some sort or filter on the resultset? Indexing will be complex in that case I believe. Great simplicity & clarity in the contents though👏.
Thanks Rano! :)
These concepts are foundational and often need to be integrated with your database of choice. So it really depends on each use case and performance requirements.
Thanks for the clean explaination. Quick question on how to go back ? nextCursor would give the next page, but when they want previous page how to go back ? should we change the query ?
To implement a back button, you’d need to keep track of your current page whenever you move to the next page. Hope this helps.
Thanks 🙂
@@ambientcoder5462 If we want to go back like 3 pages, then how do we implement that ? I can only keep tracke of current page when I move next page & after i click back i can go one page backwards but if I want to move to move back 3 - n pages how do i do it ? any help appreciated :)
Thanks a lot for such great video
Nice animations
And great content
I am gonna binge the entire playlist ☺️
And you have a sub😁
Thanks a lot and welcome! Hope you enjoy the playlist 🙂
Good video.
Although i dont think the example given for cursor based one is the best one.
It uses order by which in itself is not the best way.
Using rowid as a cursor will be much better in terms of performance.
Although that might now be the best thing for security.
Yup the example is meant to help explain the concept. Depending on the chosen database, a more appropriate value can be used.
I loved this
Well done!
Thank you! 🙂
Doesn't data base use an instant access ? Why does data base need to pass the all way from 0 to N every time? Do you know how an array works? I think data base work like that.
how many items can you say is a large dataset
for larger datasets, traversing though pages is a pain
Thank you.
Neat and awesome explanation. Thank you
Thank you!
This is wrong. You don’t know what you are talking about. First, you offset optional query was wrong. It is missing order by clause. You need to order by unique key to have readable offset.
Your so called cursor pagination is wrong also. In your example you are getting 50 records. But, your predicate might have let say 200 records with that cursor. How you are going to get next 150? . Even in this case you need to build chunks of offsets.
🤨