1
  1. I want to get the list of 1000+ users and show them in UI? Should I show all the users at once? If not, how to show them? I have seen browser hanging due to large amount of data manipulation.

  2. I want to give a special coupon to the users whose age is more than 50. Should I call database to get the users whose age is greater than 50, again?

  3. I want to manipulate a specific user data. Which data structure should I follow while getting the user data from database?

Please forgive me if you find this very noob. But please understand I want to know how to tackle this optimally! Please answer

2 Answers2

1

1- You should use Pagination to get the data in chunks. Spring Data JPA has PagingAndSortingRepository which does that. check here.

2- You can do the filtering at the FrontEnd side (React, Angular, etc..). Otherwise, you have to make a special query for those records.

3- You should use DTOs (Data Transfer Objects), which are data structures that represents your Database entities in a form suitable for the client. check here.

Jalil.Jarjanazy
  • 839
  • 1
  • 9
  • 22
0
  1. It depends on the size of your objects. 1000 record is not much if each record is small. So you can either use server side pagination, which means more queries to the server. Or you can use front-end pagination and 1 server query (This could also be optimized using server cashing)

  2. You don't have to do another query to the database, you already have the data, either on the front-end or the backend.

  3. It depends, is that some logic state that you want it to stick with the each user, then in this case use your entities. Or it is a logic that is related to representation (UI), in that case use DTOs.

Hope this helps

youness.bout
  • 343
  • 3
  • 9