Web API Pagination | Offset-based vs Cursor-based

Поделиться
HTML-код
  • Опубликовано: 16 окт 2024

Комментарии • 72

  • @pieter5466
    @pieter5466 10 месяцев назад +4

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

  • @HieuLe-qc4vi
    @HieuLe-qc4vi 3 года назад +8

    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.

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

  • @CalifornianViking
    @CalifornianViking 2 года назад +7

    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.

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

  • @enfieldli9296
    @enfieldli9296 2 года назад +2

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

  • @jonahtang
    @jonahtang Год назад

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

  • @ningfeed7118
    @ningfeed7118 3 года назад

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

  • @AkashSharma-oe9no
    @AkashSharma-oe9no 3 года назад +1

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

  • @alonefrank
    @alonefrank 3 года назад

    Very concise and clear explanation . Thanks for you contribution !

  • @mahalingappabirajdar5285
    @mahalingappabirajdar5285 Год назад

    Thanks so much explained so well

  • @IceDruid23
    @IceDruid23 2 года назад

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

  • @supa1009
    @supa1009 Год назад

    Great explanation, thank you!

  • @DuyTran-ss4lu
    @DuyTran-ss4lu 2 года назад

    amazing desmonstration

  • @MrRobotUy
    @MrRobotUy 3 года назад +1

    Really clear explanation, thank you!

  • @LuisEDITS_KLK
    @LuisEDITS_KLK 4 месяца назад

    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.

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

  • @akbarkool
    @akbarkool Месяц назад

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

  • @kimanjepatrick4656
    @kimanjepatrick4656 2 года назад

    I loved this

  • @maei1140
    @maei1140 2 года назад

    veeeery helpful!! thank you!!

  • @vaha2833
    @vaha2833 2 года назад

    Thanks a lot on this from a Junior Dev :D

  • @jofla
    @jofla 3 года назад +1

    excellent video!
    Thank you so much!

  • @ayseciftci2376
    @ayseciftci2376 2 года назад

    Thank you! So well explained!

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

  • @Michaeljamieson10
    @Michaeljamieson10 2 года назад +1

    this video is exccelent!

  • @chungtran2059
    @chungtran2059 2 года назад

    thanks for explaintion

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

  • @erlinvazquezcastellanos4052
    @erlinvazquezcastellanos4052 3 года назад +1

    Excellent content!

  • @AJTriesfifa
    @AJTriesfifa 3 года назад +1

    that was great! thanks

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

  • @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  2 года назад +1

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

  • @profhamza97
    @profhamza97 3 года назад +1

    awesome explanation

  • @ChanceMinus
    @ChanceMinus Год назад

    Thank you.

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

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

  • @osawereao
    @osawereao 2 года назад +1

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

  • @codedoctor3265
    @codedoctor3265 3 года назад

    wonderful explanation

  • @nishantkumar1983
    @nishantkumar1983 Год назад

    for larger datasets, traversing though pages is a pain

  • @Somethingsomethinglol
    @Somethingsomethinglol 3 года назад

    Well done!

  • @ank12
    @ank12 3 года назад

    Neat and awesome explanation. Thank you

  • @araz911
    @araz911 3 месяца назад

    🤨

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