Web API Pagination | Offset-based vs Cursor-based

  Рет қаралды 44,068

Ambient Coder

3 жыл бұрын

Web API pagination is crucial for building scalable APIs. There are 2 different pagination standards that you can use. It's offset-based pagination and cursor-based pagination, sometimes referred to as continuation token based pagination. It's important that you understand how these standards work and pick the right one because it's not a one size fits all thing. In this video, I give you all the details you need to pick the right one for your use case.
#WebAPIDesign #Pagination
Timecodes
0:00 - API pagination intro
3:10 - Offset-based pagination
6:50 - Cursor-based pagination
9:57 - Comparison

Пікірлер: 73
@maxxinmaze4501
@maxxinmaze4501 2 жыл бұрын
Wow man! Thank you so much for this explanation. It was easy to understand and the animations used makes things even better!
@pieter5466
@pieter5466 7 ай бұрын
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.)
@jonahtang
@jonahtang Жыл бұрын
Thank you, this is so helpful! Please continue this series!
@IceDruid23
@IceDruid23 2 жыл бұрын
Well done! Best explaination I found on topic. Made all clear. Waiting for coding version:-).
@HieuLe-qc4vi
@HieuLe-qc4vi 3 жыл бұрын
omg, the 3-hour lecture from my prof is well explained in 11 minutes. Thanks a ton!
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thank you! I’m glad you found it useful 🙂
@ZFlyingVLover
@ZFlyingVLover 2 жыл бұрын
I guess your prof doesn't really understand it then.
@chiragkalal9404
@chiragkalal9404 3 жыл бұрын
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.👍
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thanks a lot! I’m glad it helped clear your doubts! 🙂
@enfieldli9296
@enfieldli9296 2 жыл бұрын
A really well made and explained video! Thank you for sharing!
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Glad it was helpful!
@alonefrank
@alonefrank 3 жыл бұрын
Very concise and clear explanation . Thanks for you contribution !
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thank you Stefan 🙂
@ayseciftci2376
@ayseciftci2376 Жыл бұрын
Thank you! So well explained!
@ningfeed7118
@ningfeed7118 3 жыл бұрын
Thank you so much, recently got into the backend and was confused about the pagination, thank you so much
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Great to hear that you found this helpful! 🙂
@CalifornianViking
@CalifornianViking Жыл бұрын
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.
@maei1140
@maei1140 2 жыл бұрын
veeeery helpful!! thank you!!
@supa1009
@supa1009 Жыл бұрын
Great explanation, thank you!
@smokee_ms
@smokee_ms 3 жыл бұрын
Very clear explanation - well done.
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Thanks 🙂
@MrRobotUy
@MrRobotUy 3 жыл бұрын
Really clear explanation, thank you!
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Glad to know you liked it 🙂
@mahalingappabirajdar5285
@mahalingappabirajdar5285 Жыл бұрын
Thanks so much explained so well
@kimanjepatrick4656
@kimanjepatrick4656 Жыл бұрын
I loved this
@jofla
@jofla 3 жыл бұрын
excellent video! Thank you so much!
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thank you 🙂
@AkashSharma-oe9no
@AkashSharma-oe9no 3 жыл бұрын
OMG you should get more views, Thanks for explaining it so well and precisely :+1:
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Glad you liked the explanation and thanks 🙂
@NikhilSharma-xv6gx
@NikhilSharma-xv6gx 3 жыл бұрын
Thanks a lot for such great video Nice animations And great content I am gonna binge the entire playlist ☺️ And you have a sub😁
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thanks a lot and welcome! Hope you enjoy the playlist 🙂
@DuyTran-ss4lu
@DuyTran-ss4lu 2 жыл бұрын
amazing desmonstration
@chungtran2059
@chungtran2059 2 жыл бұрын
thanks for explaintion
@erlinvazquezcastellanos4052
@erlinvazquezcastellanos4052 3 жыл бұрын
Excellent content!
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thanks a lot 🙂
@ChanceMinus
@ChanceMinus Жыл бұрын
Thank you.
@AJTriesfifa
@AJTriesfifa 2 жыл бұрын
that was great! thanks
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Thanks 🙂
@Somethingsomethinglol
@Somethingsomethinglol 3 жыл бұрын
Well done!
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thank you! 🙂
@vaha2833
@vaha2833 2 жыл бұрын
Thanks a lot on this from a Junior Dev :D
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Happy to help!
@alexandre3932
@alexandre3932 2 жыл бұрын
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 !
@Michaeljamieson10
@Michaeljamieson10 2 жыл бұрын
this video is exccelent!
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
I’m happy to hear that. Thanks!
@codedoctor3265
@codedoctor3265 3 жыл бұрын
wonderful explanation
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thanks! Glad you liked it :)
@mrtechnology8028
@mrtechnology8028 3 жыл бұрын
awesome explanation
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
Thanks! 🙂
@osawereao
@osawereao 2 жыл бұрын
I'm putting this comment here because I enjoyed this video on API Pagination
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Glad to hear it!
@ank12
@ank12 2 жыл бұрын
Neat and awesome explanation. Thank you
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Thank you!
@michaizdebski8373
@michaizdebski8373 3 жыл бұрын
I did enjoy watchin all your videos. I miss information at least about rough estimate what means big data set etc.
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
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!
@ranoscope8241
@ranoscope8241 3 жыл бұрын
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👏.
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
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.
@luisdmoralesh
@luisdmoralesh 2 ай бұрын
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.
@ankk98
@ankk98 2 жыл бұрын
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.
@ambientcoder5462
@ambientcoder5462 2 жыл бұрын
Yup the example is meant to help explain the concept. Depending on the chosen database, a more appropriate value can be used.
@chmod-tf7ei
@chmod-tf7ei Жыл бұрын
how many items can you say is a large dataset
@nishantkumar1983
@nishantkumar1983 Жыл бұрын
for larger datasets, traversing though pages is a pain
@aleksandrzhilkin4800
@aleksandrzhilkin4800 Жыл бұрын
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.
@vijenderreddy1475
@vijenderreddy1475 3 жыл бұрын
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
@ambientcoder5462 3 жыл бұрын
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 🙂
@vijenderreddy1475
@vijenderreddy1475 2 жыл бұрын
@@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 :)
@saideepesh6036
@saideepesh6036 3 жыл бұрын
Hi wonderful explanation, but what about the back button request 8:51
@ambientcoder5462
@ambientcoder5462 3 жыл бұрын
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.
@saideepesh6036
@saideepesh6036 3 жыл бұрын
@@ambientcoder5462 Thank you for your reply, I think this works as per stripe's API, ?limit=10&ending_before="first response's ID"
@araz911
@araz911 17 күн бұрын
🤨
@joelmamedov404
@joelmamedov404 2 жыл бұрын
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.