Web API Pagination | Offset-based vs Cursor-based

Поділитися
Вставка
  • Опубліковано 25 лип 2024
  • 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 роки тому +8

    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 місяців тому +2

    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!

  • @HieuLe-qc4vi
    @HieuLe-qc4vi 3 роки тому +6

    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 роки тому +1

      I guess your prof doesn't really understand it then.

  • @IceDruid23
    @IceDruid23 2 роки тому

    Well done! Best explaination I found on topic. Made all clear. Waiting for coding version:-).

  • @ayseciftci2376
    @ayseciftci2376 Рік тому

    Thank you! So well explained!

  • @chiragkalal9404
    @chiragkalal9404 3 роки тому +5

    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! 🙂

  • @CalifornianViking
    @CalifornianViking Рік тому +6

    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.

  • @enfieldli9296
    @enfieldli9296 2 роки тому +2

    A really well made and explained video! Thank you for sharing!

  • @supa1009
    @supa1009 Рік тому

    Great explanation, thank you!

  • @ningfeed7118
    @ningfeed7118 3 роки тому

    Thank you so much, recently got into the backend and was confused about the pagination, thank you so much

  • @maei1140
    @maei1140 2 роки тому

    veeeery helpful!! thank you!!

  • @alonefrank
    @alonefrank 3 роки тому

    Very concise and clear explanation . Thanks for you contribution !

  • @MrRobotUy
    @MrRobotUy 3 роки тому +1

    Really clear explanation, thank you!

  • @smokee_ms
    @smokee_ms 2 роки тому +1

    Very clear explanation - well done.

  • @jofla
    @jofla 3 роки тому +1

    excellent video!
    Thank you so much!

  • @mahalingappabirajdar5285
    @mahalingappabirajdar5285 Рік тому

    Thanks so much explained so well

  • @kimanjepatrick4656
    @kimanjepatrick4656 Рік тому

    I loved this

  • @DuyTran-ss4lu
    @DuyTran-ss4lu Рік тому

    amazing desmonstration

  • @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 🙂

  • @chungtran2059
    @chungtran2059 2 роки тому

    thanks for explaintion

  • @AkashSharma-oe9no
    @AkashSharma-oe9no 3 роки тому +1

    OMG you should get more views, Thanks for explaining it so well and precisely :+1:

  • @ChanceMinus
    @ChanceMinus Рік тому

    Thank you.

  • @erlinvazquezcastellanos4052
    @erlinvazquezcastellanos4052 3 роки тому +1

    Excellent content!

  • @AJTriesfifa
    @AJTriesfifa 2 роки тому +1

    that was great! thanks

  • @Somethingsomethinglol
    @Somethingsomethinglol 3 роки тому

    Well done!

  • @vaha2833
    @vaha2833 2 роки тому

    Thanks a lot on this from a Junior Dev :D

  • @codedoctor3265
    @codedoctor3265 3 роки тому

    wonderful explanation

  • @Michaeljamieson10
    @Michaeljamieson10 2 роки тому +1

    this video is exccelent!

  • @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 !

  • @mrtechnology8028
    @mrtechnology8028 3 роки тому +1

    awesome explanation

  • @ankk98
    @ankk98 2 роки тому +1

    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 роки тому +1

      Yup the example is meant to help explain the concept. Depending on the chosen database, a more appropriate value can be used.

  • @michaizdebski8373
    @michaizdebski8373 3 роки тому +1

    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.

  • @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 :)

  • @ank12
    @ank12 2 роки тому

    Neat and awesome explanation. Thank you

  • @luisdmoralesh
    @luisdmoralesh Місяць тому

    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.

  • @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

  • @osawereao
    @osawereao 2 роки тому +1

    I'm putting this comment here because I enjoyed this video on API Pagination

  • @saideepesh6036
    @saideepesh6036 3 роки тому

    Hi wonderful explanation, but what about the back button request 8:51

    • @ambientcoder5462
      @ambientcoder5462  3 роки тому +1

      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"

  • @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.

  • @araz911
    @araz911 11 днів тому

    🤨

  • @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.