Web API Pagination | Offset-based vs Cursor-based

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ • 74

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

    • @DC01
      @DC01 2 місяці тому +1

      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.

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

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

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

  • @CalifornianViking
    @CalifornianViking 2 роки тому +9

    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.

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

  • @DeepakJiwal
    @DeepakJiwal 2 місяці тому

    Very well explained and in a concise manner. Thanks 🙏

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

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

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

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

    Thank you, this is so helpful! Please continue this series!

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

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

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

    Very concise and clear explanation . Thanks for you contribution !

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

    Really clear explanation, thank you!

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

    Great explanation, thank you!

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

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

  • @DuyTran-ss4lu
    @DuyTran-ss4lu 2 роки тому

    amazing desmonstration

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

    Excellent content!

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

    Thanks so much explained so well

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

    excellent video!
    Thank you so much!

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

    Thanks a lot on this from a Junior Dev :D

  • @akbarkool
    @akbarkool 4 місяці тому

    For cursor based - Records need to be added sequentially to DB only if we'd like to have consistent results

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

    Thank you! So well explained!

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

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

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

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

    awesome explanation

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

    veeeery helpful!! thank you!!

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

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

    this video is exccelent!

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

    that was great! thanks

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

    thanks for explaintion

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

    wonderful explanation

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

  • @LuisEDITS_KLK
    @LuisEDITS_KLK 7 місяців тому

    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.

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

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

  • @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 3 роки тому

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

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

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

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

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

    I loved this

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

    Well done!

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

  • @chmod-tf7ei
    @chmod-tf7ei 2 роки тому

    how many items can you say is a large dataset

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

    for larger datasets, traversing though pages is a pain

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

    Thank you.

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

    Neat and awesome explanation. Thank you

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

  • @shrek95372q
    @shrek95372q 5 місяців тому

    🤨