How to design API that display and filter through millions of products.REST API Filters & Pagination

Sdílet
Vložit
  • čas přidán 8. 10. 2021
  • We are very glad to start the REST APIs made easy course with the very first video on fundamentals of REST APIs, HTTP Methods, taxonomy around REST APIs etc. We hope that you get some value out of this course and these concepts help you thrive in your jobs, interviews and help you become better software engineers every day. Here are few links that you might want to refer before or during the course:
    We hope that you get some value out of this course and these concepts help you thrive in your jobs, interviews and help you become better software engineers every day.
    More on the topic:
    ✒developer.mozilla.org/en-US/d...
    ✒github.com/microsoft/api-guid...
    Previous videos to catch up on:
    ✒What is an API - • Application Programmin...
    ✒REST Standards - • What is a REST API? | ...
    ✒What is REST API - • What is a REST API? Ba...
    ------------------------------------------------------------------
    Recommendations
    ------------------------------------------------------------------
    Our full courses on youtube:
    ✒ System Design Primer Course: • System Design Primer C...
    ✒ REST APIs made easy: • REST APIs MADE EASY
    Some paid courses that we recommend:
    ✒Educative.io: bit.ly/3qnW5ku
    ✒Interviewready.io: get.interviewready.io/ (Use coupon code SUDOCODE for extra discount)
    ------------------------------------------------------------------
    About Us
    ------------------------------------------------------------------
    Created and Instructed by:
    Yogita Sharma
    ✒ LinkedIn - / yogita-sharma-83400b55
    ✒ Instagram - / sudo.code1
    ✒ Facebook - / sudo.code
    ✒ Medium - / yogita088
    Post-production(editing, thumbnail etc) managed by:
    CiKi
    ✒ Website: www.ciki.co.in
    ✒ LinkedIn: / 74735937
    Colors and design by:
    Naini Todi
    ✒ LinkedIn - / nainitodi
    Both Arpit and Yogita are software engineers and want to help other software engineers become better by providing high quality and well researched content by adding their creativity and teaching twist.
    ------------------------------------------------------------------
    Join Us
    ------------------------------------------------------------------
    Hangout with sudoCode:
    ✒Discord Server: / discord
    For business:
    ✒Email: sudocode.yogita@gmail.com

Komentáře • 99

  • @halconElectrico
    @halconElectrico Před rokem

    Your explainations are the best, right to the point, well illustrated, real world examples. Thank you.

  • @UtkarshSinghPaliwal
    @UtkarshSinghPaliwal Před 2 lety +1

    Thanks a lot for these wonderful videos. I've become a better Engineer with the help of your videos. Keep up the awesome work 👏

  • @karfin.trader
    @karfin.trader Před 2 lety +22

    Some information on how the backend queries will manage limit and offset would have been helpful to tie in the solution end to end.

    • @anothermouth7077
      @anothermouth7077 Před 2 lety

      Same, at moment I'm making query string and based on given filters I conditionally appending where clauses. Could you let me know your approach?

    • @johnrodger5467
      @johnrodger5467 Před 2 lety

      Can validate the request param in the api using a validation library, to only accept values in the allowed range. If the request is outside the range you can either return a response to the client telling them it's an invalid request, or send the request to the DB but with the max range on the query. Something like that.
      You could also write your own DB query wrappers/facades that have the limit already set there, and only use those in the application code rather than using the DB client directly.

  • @Shreenidhi110
    @Shreenidhi110 Před 5 měsíci

    thanks alot!I was struggling to anwer these questions in interview .I must say it's a easy way to understand these concepts.

  • @hakieye5649
    @hakieye5649 Před rokem

    Wow terrific to the point with clear and clean message.

  • @UtkarshSinghPaliwal
    @UtkarshSinghPaliwal Před 2 lety +16

    Please also make a few videos on Low Level Design and CDNs.

  • @iyakkaprivatelimited5735
    @iyakkaprivatelimited5735 Před 2 lety +1

    This explanation is so valuable thank you for that , also I would like to suggest if possible to do a video demo with a limited paging server response for example : API like Zoho, or deluge code based API's , how to use the explained methods on a study case like this

  • @WOYGx1010
    @WOYGx1010 Před rokem

    You did a great job with this video, thank you

  • @jinalpatel9154
    @jinalpatel9154 Před 2 lety

    This is nice topic. Sometime I feel that pure REST approach is not suitable for business need. It mainly revolve around single entity but business application has complex need like to filter. Let's say for example Employee Belong to specific company and organization and there are multiple attribute associated with that and we have to pass multiple filter attribute. I feel that sometime pragmatic approach will make more sense and expose end-point like /search / filters etc will make more sense.

  • @utkarshconscious
    @utkarshconscious Před 2 lety +11

    This is really wonderful explanation. I know its not in scope of this series but out of curiosity would you mind throwing some light on how backing code for pagination can be implemented? Will it use some sort of sorted cache from where it returns results based on offset and max limit or is there a better way to get this done?

  • @nihal6290
    @nihal6290 Před 2 lety +1

    Love this video.
    Can you please create a video dedicated to API Security? How do you secure an API?

  • @saurabhchopade3891
    @saurabhchopade3891 Před 2 lety

    Dope quality Explanation.

  • @vengateshan7800
    @vengateshan7800 Před 4 měsíci +1

    This video was very helpful and got more info . Thanks

  • @rjcdz06
    @rjcdz06 Před 8 měsíci +1

    Great and clear explanation 👏👏 Thanks a lot

  • @saurabhchopade3891
    @saurabhchopade3891 Před 2 lety

    Thanks for posting this one

  • @m13m
    @m13m Před 10 měsíci

    In backend for offset and limit pagination we can use db limit and offset parameter while creating a query to fetch that many rows and this quite inefficient in certain scenarios.
    Keyset pagination which is quite efficient but can’t directly query a particular page. Either go forward or backward in rows with a particular limit.

  • @abhijitdixit1589
    @abhijitdixit1589 Před 2 lety

    One more way to reduce payload is sending it back as a stream, can you share use case for the same?
    Could it be video/audio streaming?

  • @akashrulz30
    @akashrulz30 Před 2 lety

    Thank you so much 🔥

  • @sidhanshuraghuvanshi1
    @sidhanshuraghuvanshi1 Před 6 měsíci +1

    Expecting implementations of concepts as well in all videos

  • @nocaoconstantino3555
    @nocaoconstantino3555 Před rokem

    Great. Wonderful explanation.......

  • @raamch
    @raamch Před 2 lety

    Wonderful explanation

  • @haseebalamrafiq5894
    @haseebalamrafiq5894 Před 2 lety

    mam you explain awesome. Thanks

  • @shashankshekhar2736
    @shashankshekhar2736 Před 2 lety

    Amazing explanation

  • @user-vr8hg1eo4d
    @user-vr8hg1eo4d Před měsícem

    Thank you so much for the effort.
    appreciate it
    Loay from Egypt

  • @keshavsethi1610
    @keshavsethi1610 Před 2 lety

    just one word Awesome.

  • @buckybarnes9135
    @buckybarnes9135 Před 2 lety +2

    by your presentation we easily got the concepts, thanks to your editor😅😅

  • @naveensharma9834
    @naveensharma9834 Před rokem +1

    Clear and crisp explanation but I've one question. Do we need to hit db for every request, Is it a good idea ? If not then what are the other ways we fetch x amount to data in once(certain threshold) and serve in 20-20 chunks ?

    • @m13m
      @m13m Před 10 měsíci

      Definitely we could fetch a threshold number of rows and warumup your cache and grab any new data only through but offset-limit pagination is quite inefficient imagine there is no cache is such case every single query of limit and offset you are hitting db grabbing all the rows and then applying limit and offset on them.
      Also if you are inserting new items as well there can be cases where you could have duplicate items among your list with offset-page pagination
      Other technique that could be useful keyset pagination where you can’t actually pass offset but can behaviour of pagination with previous and next page with a certain limit just that can’t jump to a particular page but definitely traverse them limit you have set at a time.

  • @maniac1441
    @maniac1441 Před rokem +1

    greatly explained

  • @erased1972
    @erased1972 Před 2 lety

    Very helpful video

  • @rahulsen002
    @rahulsen002 Před rokem

    Found 2 channels useful so far .. Ur channel and another.. kudos

  • @chollangimanisha3148
    @chollangimanisha3148 Před 11 měsíci

    Hi,your explanation is good.
    I have issue with pagination. I using one azure api to get all items. In azure portal, 500 items are there but I am getting 200 items while querying api. I applied limit and offset as well but not working. Please help.

  • @sergiothinks2
    @sergiothinks2 Před 2 lety

    amazing video thank you!

  • @gouravkumarshaw5467
    @gouravkumarshaw5467 Před rokem

    Thanks !!

  • @unmeshvpatil
    @unmeshvpatil Před rokem

    Does api works to show products which are on low prices due to price error listed on amazon or flipkart?

  • @gurucharans9629
    @gurucharans9629 Před rokem

    Mam'm how could I understand my frontend before making backend server. If I created a registration page and login page are on different pages then it's important to make the same thing on the backed side. So, I will have to login and registration page (register, update, compare password pages) are on the different pages or same page in backed side.

  • @kapilrules
    @kapilrules Před 2 lety

    Hi Yogita In case of pagination are all responses for all pages cached at server side at once? And then they are dispatched to client page by page as per the request? If they are cached on Server side when will the cache cleared? Thank you for all your videos 🙏

    • @_tachyons
      @_tachyons Před 2 lety +1

      This is unlikely, it is mostly implemented by directly executing query on database, caching layer is added to improve performance, but caching entire thing in the cache defeats the purpose of caching

  • @joe0212
    @joe0212 Před rokem

    Nice. Any video on cursor vs offset based pagination

  • @javaeeguy
    @javaeeguy Před 2 lety +1

    Can you please cover REST API security also?

  • @kw5218
    @kw5218 Před rokem

    Explaination is excellent please provide practical video if possible

  • @pranavbhat29
    @pranavbhat29 Před 2 lety

    Is there any specific form of response code sent by the server when the limit set by the client in the query param is larger than the max limit set in the server. I was thinking if it will send either of 400 ( Bad request ) or 413 ( payload too large ), but again you get a response with valid set of items in the server. So it seems to use some specific 2XX code itself. Could you please suggest or throw some pointer on what that might be?

  • @adeshgangwar3555
    @adeshgangwar3555 Před 2 lety

    Hi
    I have a quick question.
    So if i have 50 orders fetched from api and are available in dom. Now i want to implement search the order by id. In this case shall I do a internal filter in the dataset or shall I fetched filtered data from api?
    What would be the best approach to do it?

    • @AjaSiva
      @AjaSiva Před 2 lety

      Fetch it from the api. You may not know what ids are there in the current data you fetched. So it can give no result too if searched by id. Also id's are indexed in databases. So fetch call is not that costly.

  • @rajankumarsingh9137
    @rajankumarsingh9137 Před 2 lety +1

    On the server in every request we will be fetching all the data(from database) then paginating it right, assuming no caching is done??

    • @UtkarshSinghPaliwal
      @UtkarshSinghPaliwal Před 2 lety +3

      No. We can write the DB query which take the limit and offset numbers as arguments and fetch only the required data from the Database.

    • @shailjakantupadhyay5183
      @shailjakantupadhyay5183 Před 2 lety

      We never do that, consider server contains trillion data in table if you fetch all the data then it will go down. Read @Utkarsh comment.

  • @luxurymusic1051
    @luxurymusic1051 Před rokem +1

    hey i was asked a question where i told about offset for pagination, but interviewer told the data is added on api all the time, so when i call the next page , i might get the same data in the next offset as well coz new data was appended by time i clicked on next page, so how to handle such cases???

    • @II-ii2um
      @II-ii2um Před rokem

      simple function that checks if the previous data shown != the new data being shown this time?
      Source: Copy-Paste Buffers in Systems use this all the time to prevent the same shit from being copied and pasted over and over again...
      Have you figured out a better answer for this yet?

  • @DeepakJangra-up8ek
    @DeepakJangra-up8ek Před 2 lety

    Critical: what if you request, say first 10 (sorted by latest) orders and then 1 new order received. Now if you request next page then 1 order (1st of second page) will be repeated because thats 11th order now (not 10th anymore). How can we fix that.

    • @_tachyons
      @_tachyons Před 2 lety

      This is not necessarily a technology issue, this could be an expected behavior as well. But if you want more predictable behavior use cursor based pagination

  • @hammerod
    @hammerod Před rokem

    Thank u

  • @stephenselvaraj8960
    @stephenselvaraj8960 Před 2 lety +1

    Super :)

  • @AnikashChakraborty
    @AnikashChakraborty Před 2 lety

    How do I get to know till what number should I make the pagination buttons? Because if I don't specify it then the next button will return an empty page sometime in other words the grt request will return an empty array

    • @ivocosta7281
      @ivocosta7281 Před 2 lety +1

      When you receive paginated data, the resultset should also set total records , what is the pagesize. Once you have these two data point, you know which will be the last page

  • @cut-a-lyst
    @cut-a-lyst Před 2 lety

    can we send a json data in filter if filtering data is complex?
    I currently POST and json body for it currently

    • @UtkarshSinghPaliwal
      @UtkarshSinghPaliwal Před 2 lety

      Generally, there sbould not be a payload associated with a GET request. For a POST request, filtration might not be something that is required in the usual scenarios.

  • @typg93
    @typg93 Před rokem

    how does this compare to graphQL?

  • @subee128
    @subee128 Před měsícem

    Thanks

  • @dragonlordsaviour7005

    you're super underrated

  • @yashkhandelwal9926
    @yashkhandelwal9926 Před 2 lety

    Are there any issues if we use post instead of get in this and send all the required data in requestBody rather than query params?

    • @_tachyons
      @_tachyons Před 2 lety

      That will be violation of rest conventions, but if the params is too big, then you may have to use POST

    • @UtkarshSinghPaliwal
      @UtkarshSinghPaliwal Před 2 lety

      Bad Practice

  • @praveenj3112
    @praveenj3112 Před 2 lety

    It's clear ..but there is more link to fetch more data in some pagination APIs

  • @rahul2142
    @rahul2142 Před rokem

    Mam have you created video on implementation?

  • @ChandanKumar-ou9fr
    @ChandanKumar-ou9fr Před 2 lety

    Designing the APIs are fine, but how to implement such things? What is the right approach. Let's assume that I am building an ecommerce site and where from the database I want top 20 filtered items, how to do that in code? Thanks for the awesome content.
    PS: All theory and no code, makes jhony a dull boy 😉

  • @gurusamy4523
    @gurusamy4523 Před 10 měsíci

    Hi teacher thanks❤

  • @kunalshah2331
    @kunalshah2331 Před rokem

    What is there is no pagination.. the data is loaded based on the user scrolling the screen..

  • @venkatshk
    @venkatshk Před 2 lety

    please cover sorting also

  • @sumanthkeith1
    @sumanthkeith1 Před 2 lety

    I have few questions on pagination.
    Can you explain about the page count. How to determine how many number of pages for each query. Say the query returned 90 rows, and if the results per page is 10. I need to show 9 pages (1 2 3 4 .. 9)
    2. See this scenario. I have a query which returns 100 records and on top of that I need to apply some business logic and filter some data, so after filter I got 70 records. Now how pagination work when user click on page 2. (Point to be noted there might be thousands os records returned at a time for a query).

    • @UtkarshSinghPaliwal
      @UtkarshSinghPaliwal Před 2 lety

      Pagination should be applied on the final records being exposed to the clients. In the case where only 70 records are accessible by the client, pagination should create only 7 pages in totality. Moreover, in these cases, the client should never know that there are actually 100 records on top of which a biz. logic filters them down to 70. Otherwise, this would be an abstraction leak.

    • @sumanthkeith1
      @sumanthkeith1 Před 2 lety

      @@UtkarshSinghPaliwal yup I agree. But my question is when I click on page two, should query the db get 100 and apply business logic again to filter and show the contents of next set of records?? If we do this there will be performance impact.
      One solution is to store the filtered logic and Show the 2 nd page and so on.
      Should we use Redis or java cache us my next question.

    • @UtkarshSinghPaliwal
      @UtkarshSinghPaliwal Před 2 lety +1

      @@sumanthkeith1 That's a pretty decent problem statement. We need to paginate and we don't have the records to send back without applying some business logic. In this case I'd say to choose either of two things, may be not use pagination at all or cache the indexes of the records and some meta if required. I'm presuming that querying data more than once is very expensive so that logic is not an option. Now with both the cases suggested, two problems arise, one with both the paths. If no pagination used, data may not even fit in a single response in which case you may provide a download link instead. In the other case of caching, you'll have to deal with all the caching related issues like data consistency etc. So you'll have to choose either of the two evils depending on your particular costs and usage.

  • @pradeepcreations8669
    @pradeepcreations8669 Před 10 měsíci

    will this work for mongodb?

  • @AbhishekJain118
    @AbhishekJain118 Před rokem

    You did not discuss this scenario: if client request for 100 items and server max-limit is 20, how client will be able to request items 20 to 39 in the next request? How client will set its offset ?
    I am assuming client logic should have offset=lastoffset+numberOfItemsReceived

    • @sudocode
      @sudocode  Před rokem

      That’s implied my friend.

  • @vidhanchandra3997
    @vidhanchandra3997 Před 2 lety

    💕

  • @NamathuUla
    @NamathuUla Před 2 měsíci

    Thank you for your video but there is some limitation in LIMIT and OFFSET. it will be huge cost involved for RU/s

  • @mythiyen1386
    @mythiyen1386 Před 2 lety

    CDN can you share

  • @itsme_ry
    @itsme_ry Před 2 lety +1

    Nic mam

  • @umangbehl8152
    @umangbehl8152 Před 3 měsíci

    nice

  • @kumaramresh7905
    @kumaramresh7905 Před 2 lety +1

    actually i learned these terms pagination, limit, offset, filters while learning DBMS and i think they're more related to that that rest Api

  • @jagansiram2529
    @jagansiram2529 Před 2 lety

    Didn't work.. getting complete result

  • @getthenetfishing7130
    @getthenetfishing7130 Před 6 měsíci

    Do you offer a service to integrate an API from my distributor to my website for orders and dropshipping

  • @andiamakaza24
    @andiamakaza24 Před 2 lety +1

    U looks like NAIROBI of money heist 😀

  • @ilakkiya.s1142
    @ilakkiya.s1142 Před rokem

    😊

  • @keaganferrao
    @keaganferrao Před 4 měsíci

    Using an OFFSET for huge data will still be inefficient for MILLIONS of rows as the database still needs to skip all the rows specified by offset. I expected you to give a solution to this problem in this video as the title specified "millions".

  • @sujan_kumar_mitra
    @sujan_kumar_mitra Před 2 lety +1

    Is using OFFSET a good idea to skip resources? I have heard that using OFFSET in SQL can reduce the performance of DB as if there are a large no. of records, the DB has to pull the tuples from the disk but not include them in the RESULT SET

  • @mainuddinali9561
    @mainuddinali9561 Před 7 měsíci

    in this video u r looking lean

  • @rajeshpatil3690
    @rajeshpatil3690 Před rokem

    Nice explanation but only for a very primitive audience to understand. It does not contain any technical details on how it works or implemented . If you could add more details on server side services to map to your URI examples that would be helpful.

    • @sudocode
      @sudocode  Před rokem

      Sure, you can create a video on that and I will be happy to endorse it 😅