Posts

Showing posts with the label Spring Boot

Transaction Management in Microservices

https://medium.com/@walkingtreetech/transaction-management-in-microservices-ab09b0cb803b https://dzone.com/articles/transactions-in-microservices

Inter-Process Communication in a Microservices Architecture

https://dzone.com/articles/building-microservices-inter-process-communication-1 https://dzone.com/articles/building-microservices-inter-process-communication-2

Generating unique IDs in a distributed environment at high scale

Existing Solutions UUID UUIDs  are 128-bit hexadecimal numbers that are globally unique. The chances of the same UUID getting generated twice is negligible. The problem with UUIDs is that they are very big in size and don’t index well. When your dataset increases, the index size increases as well and the query performance takes a hit. MongoDB’s ObjectId MongoDB’s ObjectIDs  are 12-byte (96-bit) hexadecimal numbers that are made up of - a 4-byte epoch timestamp in seconds, a 3-byte machine identifier, a 2-byte process id, and a 3-byte counter, starting with a random value. This is smaller than the earlier 128-bit UUID. But again the size is relatively longer than what we normally have in a single MySQL auto-increment field (a 64-bit bigint value). Database Ticket Servers This approach uses a centralized database server to generate unique incrementing IDs. It’s like a centralized auto-increment. This approach is used by  Flickr . The problem with t...

What’s the difference between @PathVariable, @PathParam, and @RequestParam?

Even though  @PathVariable  and  @RequestParam  are both used to extract values from the URL, their usage is largely determined by how a site is designed. The  @PathVariable  annotation is used for data passed in the URI (e.g. RESTful web services) while  @RequestParam  is used to extract the data found in query parameters. If we had chosen to use query parameters, our URL would be: http://localhost:8080/orders?id=100 This would be implemented in a controller method like the following: @GetMapping("/orders") @ResponseBody public String getOrder(@RequestParam(value = "id", required = true) String id) {   return "Order ID: " + id; } These annotations can be mixed together inside the same controller. @PathParam is a JAX-RS annotation that is equivalent to @PathVariable in Spring.   

Spring Boot Annotations

@SpringBootApplication We use this annotation to  mark the main class of a Spring Boot application : 1 2 3 4 5 6 7 @SpringBootApplication class VehicleFactoryApplication {        public static void main(String[] args) {          SpringApplication.run(VehicleFactoryApplication. class , args);      } } @SpringBootApplication  encapsulates  @Configuration ,  @EnableAutoConfiguration , and  @ComponentScan annotations with their default attributes. @EnableAutoConfiguration @EnableAutoConfiguration , as its name says, enables auto-configuration. It means that  Spring Boot looks for auto-configuration beans  on its classpath and automatically applies them. Note, that we have to use this annotation with  @Configuration : 1 2 3 @Configuration @EnableAutoConfiguration class VehicleFactoryConfig {} ...