02. Building microservices with Spring Boot Flashcards

1
Q

What are the characteristics of a microservice-based architecture ?

A
  • Constrained
  • Loose coupled
  • Abstracted
  • Independent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does it mean that a mircroservice must be constrained ?

A

Microservices have a single set of responsibilities and are narrow in scope. Microservices embrace the UNIX philosophy that an application is nothing more than a collection of services where each service does one thing and does that one thing really well.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does it mean that a mircroservice must be Loose coupled ?

A

A microservice-based application is a collection of small services that only interact with one another through a non–implementation specific interface using a non-proprietary invocation protocol (for example, HTTP and REST). As long as the interface for the service doesn’t change, the owners of the microservice have more freedom to make modifications to the service than in a traditional application architecture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does it mean that a mircroservice must be Abstracted ?

A

Microservices completely own their data structures and data sources. Data owned by a microservice can only be modified by that service. Access control to the database holding the microservice’s data can be locked down to only allow the service access to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does it mean that a mircroservice must be Independent ?

A

Each microservice in a microservice application can be compiled and deployed independently of the other services used in the application. This means changes can be isolated and tested much more easily than with a more heavily interdependent, monolithic application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When building a microservices architecture, a project’s architect focuses on three key tasks:

A
  1. Decomposing the business problem
  2. Establishing service granularity
  3. Defining the service interfaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the guidelines for identifying and decomposing a business problem into microservice candidates ?

A
  1. Describe the business problem, and listen to the nouns you’re using to describe the problem
  2. Pay attention to the verbs.
  3. Look for data cohesion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can you explain how to describe the business problem ?

A

Using the same nouns over and over in describing the problem is usually an indication of a core business domain and an opportunity for a microservice. Examples of target nouns for the EagleEye domain from chapter 1 might look something like contracts, licenses, and assets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can you explain what does it means to Pay attention to the verb ?

A

Verbs highlight actions and often represent the natural contours of a problem domain. If you find yourself saying “transaction X needs to get data from thing A and thing B,” that usually indicates that multiple services are at play. If you apply to EagleEye the approach of watching for verbs, you might look for statements such as, “When Mike from desktop services is setting up a new PC, he looks up the number of licenses available for software X and, if licenses are available, installs the software. He then updates the number of licenses used in his tracking spreadsheet.” The key verbs here are looks and updates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can you explain what does it means to Look for data cohesion ?

A

As you break apart your business problem into discrete pieces, look for pieces of data that are highly related to one another. If suddenly, during the course of your conversation, you’re reading or updating data that’s radically different from what you’ve been discussing so far, you potentially have another service candidate. Microservices should completely own their data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What concepts will you follow to define microservices granularity ?

A
  1. It’s better to start broad with your microservice and refactor to smaller services— It’s easy to go overboard when you begin your microservice journey and make everything a microservice. But decomposing the problem domain into small services often leads to premature complexity because microservices devolve into nothing more than fine-grained data services.
  2. Focus first on how your services will interact with one another— This will help establish the coarse-grained interfaces of your problem domain. It’s easier to refactor from being too coarse-grained to being too fine-grained.
  3. Service responsibilities will change over time as your understanding of the problem domain grows— Often, a microservice gains responsibilities as new application functionality is requested. What starts as a single microservice might grow into multiple services, with the original microservice acting as an orchestration layer for these new services and encapsulating their functionality from other parts of the application.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the indicators of a bad microservice design =

A
  1. A service with too many responsibilities
  2. The service is managing data across a large number of tables. If you find yourself persisting data to multiple tables or reaching out to tables outside of the immediate database, this is a clue the service is too big. A microservices should own no more than 3 to 5 tables
  3. Too many test cases
  4. The microservices in one part of the problem domain breed like rabbits—If everything becomes a microservice, composing business logic out of the services becomes complex and difficult because the number of services needed to get a piece of work done grows tremendously. A common smell is when you have dozens of microservices in an application and each service interacts with only a single database table.
  5. Your microservices are heavily interdependent on one another—You find that the microservices in one part of the problem domain keep calling back and forth between each other to complete a single user request.
  6. Your microservices become a collection of simple CRUD (Create, Replace, Update, Delete) services—Microservices are an expression of business logic and not an abstraction layer over your data sources. If your microservices do nothing but CRUD-related logic, they’re probably too fine-grained.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name 4 guidelines that can be useful to design service interface:

A
  1. Embrace the REST philosophy— The REST approach to services is at heart the embracing of HTTP as the invocation protocol for the services and the use of standard HTTP verbs (GET, PUT, POST, and DELETE).
    Model your basic behaviors around these HTTP verbs.
  2. Use URI’s to communicate intent— The URI you use as endpoints for the service should describe the different resources in your problem domain and provide a basic mechanism for relationships of resources within your problem domain.
  3. Use JSON for your requests and responses— JavaScript Object Notation (in other words, JSON) is an extremely lightweight data-serialization protocol and is much easier to consume then XML.
  4. Use HTTP status codes to communicate results— The HTTP protocol has a rich body of standard response codes to indicate the success or failure of a service. Learn these status codes and most importantly use them consistently across all your services.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In a Spring Boot application, you can define Spring Beans by:

A
  1. Annotating a Java class with a @Component, @Service or @Repository annotation tag
  2. Annotating a class with a @Configuration tag and then defining a constructor method for each Spring Bean you want to build with a @Bean tag.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is a Controller in a spring boot app ?

A

A Controller class exposes the services endpoints and maps the data from an incoming HTTP request to a Java method that will process the request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What @RestController do ?

A

This annotation automatically handles the serialization of data passed into the services as JSON or XML (by default the @RestController class will serialize returned data into JSON). Unlike the traditional Spring @Controller annotation, the @RestController annotation doesn’t require you as the developer to return a ResponseBody class from your controller class. This is all handled by the presence of the @RestController annotation, which includes the @ResponseBody annotation.

17
Q

What do you use @RequestMapping annotation ?

A

The @RequestMapping annotation is used to tell the Spring container the HTTP endpoint that the service is going to expose to the world. When you use the class-level @RequestMapping annotation, you’re establishing the root of the URL for all the other endpoints exposed by the controller.

18
Q

What are the principles of Microservices ?

A
  1. A microservice should be self-contained and independently deployable with multiple instances of the service being started up and torn down with a single software artifact.
  2. A microservice should be configurable. When a service instance starts up, it should read the data it needs to configure itself from a central location or have its configuration information passed on as environment variables. No human intervention should be required to configure the service.
  3. A microservice instance needs to be transparent to the client. The client should never know the exact location of a service. Instead, a microservice client should talk to a service discovery agent that will allow the application to locate an instance of a microservice without having to know its physical location.
  4. A microservice should communicate its health. This is a critical part of your cloud architecture. Microservice instances will fail and clients need to route around bad service instances.
19
Q

What is the service assembly ?

A

This process of consistently building, packaging, and deploying

20
Q

What does a Spring Actuator module ?

A

Spring Actuator provides out-of-the-box operational endpoints that will help you understand and manage the health of your service

21
Q

What is the perspective of an Architect ?

A

Focus on the natural contours of your business problem. Describe your business problem domain and listen to the story you’re telling. Target microservice candidates will emerge. Remember, too, that it’s better to start with a “coarse-grained” microservice and refactor back to smaller services than to start with a large group of small services. Microservice architectures, like most good architectures, are emergent and not preplanned to-the-minute.

22
Q

What is the perspective of a Software Engineer ?

A

The fact that the service is small doesn’t mean good design principles get thrown out the window. Focus on building a layered service where each layer in the service has discrete responsibilities. Avoid the temptation to build frameworks in your code and try to make each microservice completely independent. Premature framework design and adoption can have massive maintenance costs later in the lifecycle of the application.

23
Q

What is the perspective of a DevOps Engineer ?

A

Services don’t exist in a vacuum. Establish the lifecycle of your services early. The DevOps perspective needs to focus not only on how to automate the building and deployment of a service, but also on how to monitor the health of the service and react when something goes wrong. Operationalizing a service often takes more work and forethought than writing business