Implementing the get services
Let's take our product
project developed in Chapter 2, Writing Your First Cloud-Native Application, forward. We will incrementally enhance it while discussing the concepts.
Let's think carefully about the database of our two services. getProduct
returns the product information, while getProducts
searches a list of products that fall into this category. To begin with, for simple and standard requirements, both queries can be answered by a single data model in a relational database:
- You would store a product in a product table with a fixed number of columns.
- You would then index the category so that the queries against it can run quickly.
Now, this design will be fine for most requirements for an average-sized company.
Simple product table
Let's use a product table in a standard relational database and access it in our service using Spring Data. Spring Data provides excellent abstractions to use the Java Persistence API (JPA) and makes coding data access objects (DAO...