MicroService – Brief Introduction

This post will focus on what Microservices are, why is it so famous these days, what are the positive and negative aspects of these services and what all area we will try to cover in future posts.

In addition, will share few youtube links, which are quite helpful to understand this concept. As a developer, I will say it is just one of the way how well we are packaging or modularizing code.

First of all, I would like to tell you, that I am inclined toward MicroServices, so most the things you find here will kind be in favor of these.But I will discuss all the challenges which you might face when you try to follow the awesome journey of MicroServices.

What is Micro Service?

Rather than going for a definition we will try to find the what are the common characteristics of Mirco Services.

In simple terms, you can think of a very small independent project capable of performing all the task.So If in a monolith you have various responsibilities, let each of this responsibility as a separate service.What responsibility does not have any concrete boundary. So this lets to the rise of the new question, how big or how small the micro services should be.Some people says it should be small enough to be handled by one developer, some say it should not be more than then few hundred line of code.To solve this, we will term service as a micro service if they have few of the properties/characteristics mention below.

Characteristics of MicroServices

  • Can be upgraded or rewrite independently.
  • Have fault tolerance and monitoring mechanism.
  • Each service is a complete Product.
  • Should have their own Data Management.
  • Should be easily replacable.
  • Should only expose the endpoint to dependendant services.

 

What a fuss is this, and Why is it becoming so popular these days?

As we all know that it is simple to solve number of small problems and then join all of them to solve the bigger problem.What we call is devide and conqure. Only problem in this approch is we need a very good merger technique to have a successful solution.With Devops of today(Docker,Kubernets,Mesos) it have been made possible to developer to manage large number of services and there deployment.Even it has helped to increase the resource utilization , which have further decreased the cost of maitaining multiple services.

Pros

  • It break the problem into smaller problem, helping developer to solve it more accuratley and in most optimized manner.
  • Partial Deployment and Partial Upgradation of Application is possible.
  • Help to reduce the develoment time.
  • We can easily rewite any service .
  • Services can be written in any programming languages , and we can easily try new progamming language.
  • Easier to find and fix bottleneck in the system.
  • Maintainance and Bug fix can be simper.
  • Test scope increases as we have to test smaller units independently.
  • CI/CD can be implemented easily.
  • Preserve modularity.

Cons

  • It increases the Devops activities.
  • Organization have to monotor and handle large number of sevices.
  • Service Discovery and trackng of request can be tidious task.
  • Need change in Oraganization culture.
  • Developer have to work more closely with devops , in order to make the development more stream line.
  • Need advance Devops.
  • Since it is kinda a new, not every one have clear idea what is a baoundary of MiroService.

Some Great Videos to give more insight.

 

Topics to be cover in upcoming blogs

  • Modules vs Microservices
  • How to share domain between different micro services
  • Should we have a common DAO[Database ] layer for every service or each service should have their own DAO layer?
  • All micro services in single Git Repo or they should have separate Git Repo
  • How to do monitoring of Micro Services.
  • How to track the flow of any particular request in real time between services.
  • Containerization of micro services.
  • Creating an environment of  Containerization service, which is self-deployed.
  • When to go for Micro Services.
  • How to shift from Monolith to Microservices.
  • How to perform Integration testing involving couple of Microservices as dependencies.
  • Distributed logging for Services.

Dockerize Spring Boot Application

This blog will help the audience to enable them to create docker image from a Spring boot Application.We have created a Spring Boot with maven.

We have already created the code repository. This repository contain 3 branches

1.Master: – Vanilla Spring Boot with Web Module

2.Controller-Test: – Master with test Rest repository.

3.Docker-Support :- Added docker support to Controller-Test branch

Prerequisite

  • Spring Boot Knowledge
  • How to create simple DockerFile

Here we will see what changes are required to add docker support to Spring Boot Application. It is the changes required to create Docker-Support branch from Controller-Test branch.

Changes Required in Pom

We need to add below mention plugin in the pom.

<plugin>
   <groupId>com.spotify</groupId>
   <artifactId>docker-maven-plugin</artifactId>
   <version>0.2.3</version>
   <configuration>
      <imageName>horizon/${project.artifactId}</imageName>
      <dockerDirectory>/</dockerDirectory>
      <resources>
         <resource>
            <targetPath>/</targetPath>
            <directory>/</directory>
            <include>${project.build.finalName}.jar</include>
         </resource>
      </resources>
   </configuration>
</plugin>

Add DockerFile in the project path

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD target/docker-0.0.1.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8080

There are two ways to create a docker image from the current source now.

1.Create docker image using maven plugin [can also be used using Jenkin worklow]

Run the command from project directory:- mvn clean package docker:build

2.Create docker image using docker build command

Run mvn install:- mvn clean install

Create docker image by executing the following command from project directory:

docker build  -t  docker.demo:latest  .

ThoughtWorks-interview experience

Got a call from a consultant,

I am sharing my interview experience for the same with you.

  1. Telephonic [30 mins]
    1. Current Project, and how PMS work internally.
    2. The difference between quick sort and merge sort.
    3. Which sorting did java use internally?
    4. When to user Interface, and Abstract classes.
    5. How to make class Immutable, and if immutable class contain a list, how to handle it.
  2. Coding[With Laptop coding]
    1. Write a program to full fill following problem: two(times(three())) or nested cases also.All the operator should be there.[logic was important].Click Here to get the complete code of this problem
  3. Coding[With Laptop coding]
    1. Write a code to compute the cost of the checkout cart, have many items with quantity, the group of items can have the special price. Every item has there individual price.[Focus on domain design]
  4. F2F Interview
    1. Current project design, architecture, your role.
    2. Difference btw soap and rest service.
    3. Domain design for a ROOM.
    4. Multi-thread simple question,
    5. DB designing simple.
  5. F2F Interview
    1. this was more of a discussion rather than the interview, more related to culture and personality.They will try to understand who you are, what are your goals.Are you  right person or not for ThoughtWorks
  6. F2F Interview
    1. It was related to the 3 pillars that ThoughtWorks build on, and try will try to understand your point of view on various social issues
  7. Aptitude Test
    1. There are around 50 questions, you  have to complete as much as question in 12 min
  8. Logical Test
    1. There are 13 question which have to completed in 1 hour.
A major focus will be given to Domain Design, how the class is created and how the will interact.
OOPS, concepts are important.Name of the classes matter.
If really want to crack Thoughtworks, please check few books.

Get YOUTUBE video details from the URL of the video.

Summary : This code is to get the information of the youtube video using the URL of the Video.

Language: PHP
Require JSON parsing or XML parsing .

Note : information can be get from url,we are taking json format

URL FORMAT http://www.youtube.com/oembed?url=%5BURL of the video]&format=xml[or json]
&format will decide the output of the query.

Information to be fetched; Title, thumbnail, author name , provider name , author url, etc.

PHP code to print the data :

//url of the video you want to fetch the data.
$url = ‘https://www.youtube.com/watch?v=RalvLaiSZa0&#8217;;
$youtube = ‘http://www.youtube.com/oembed?url=&#8217;.$url.’&format=json’;

//get the json content, we have put ‘@’ to suppress the warning when url is not correct.
$content = @file_get_contents($youtube);
if($content === false){
echo “Some Error in URL , pls check it.Pass the valid URL”;
}else{
/parse the json content
$data = json_decode($content, TRUE);

//get all the required content fron data, it is an array contain all the information.
echo $data[‘title’];
//echo $data[‘html’];
echo $data[‘author_url’];
echo $data[‘provider_name’];
echo $data[‘provider_url’];
echo $data [‘thumbnail_url’];

//there may be cases when any of these information may not present , in that case you have to handle it using isset.
if(isset($data[‘type’])){
echo $data[‘type’];
}

}

///method got the same if you want to reuse the code .

getVideoDetailFromUrl($url){

$youtube = ‘http://www.youtube.com/oembed?url=&#8217;.$url.’&format=json’;

//get the json content
$content = @file_get_contents($youtube);
if($content === false){
echo “Some Error in URL , pls check it.Pass the valid URL”;
}else{
//parse the json content
$data = json_decode($content, TRUE);
return $data;
}
}

 

NOTE: Don’t forget to Enable extension=php_curl.dll in your php.ini
To Test it online you can use “http://codepad.viper-7.com/&#8221; to run the code .

NEXT CODE : GET ALL THE VIDEO FROM THE AUTHOR OF PARTICULAR VIDEO.[AUTHOR DETAIL ALSO].

 

Important URL may be connected

Given an array, find all the subsets

int arr[] = {1,2,3,4,5};
int level= 0;

for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
subset(arr[i]+””,i+1,arr);

}
}

private void subset(String i, int level,int[] arr) {

for (int j = level; j < arr.length; j++) {
System.out.println(i+””+arr[j]);
subset(i+””+arr[j],j+1,arr);

}

Find the all the lexical pair from the given array of strings.

lexical pairs

 

Vector<String> v = new Vector<String>();
Set<String> s = new HashSet<String>();
v.add(“Resistance”);
v.add(“Ancestries”);
v.add(“Gainly”);
v.add(“Laying”);
v.add(“test”);
v.add(“troop”);
v.add(“Amit”);
v.add(“Mait”);
v.add(“Self”);
v.add(“Taim”);
Boolean lexical = false,found = false;
System.out.println(“case 2”);

int lenght = v.size(),count = 0;

for (int i = 0; i < v.size(); i++) {
String source = v.get(i);

source = source.toLowerCase();
char[] sourceWord = source.toCharArray();
Arrays.sort(sourceWord);
source = new String(sourceWord);
//System.out.println(“source “+source);
count =0;
for (int j = i+1; j < v.size(); j++) {

String target = v.get(j);
target = target.toLowerCase();
char[] targetWord = target.toCharArray();
Arrays.sort(targetWord);
target = new String(targetWord);

if(source.equals(target)){
lexical = true;

System.out.print(v.get(i)+” “);
System.out.println(v.get(j));
continue;
// v.remove(v.get(j));

}

}
if(count>0)
System.out.println(“”);
}

if(!lexical){
System.out.println(“No such pairs”);
}

Given a matrix with each cell containing each number of candies, and a constraint that you can move only right or down, from the top left corner to the bottom right corner, find the path that gets you maximum candies.

Note: This result will print the all the possible path cost , you can fetch the path with maximum candies.

 

int matrix[][] = {{0,5,7},{7,9,1},{2,7,11}};
int rows = matrix.length,column = matrix[0].length;
System.out.println(“rows : “+rows );
System.out.println(“columns : “+column);
int TotalSum = 0,sum=0;

FindTheTotalSum(0,0,sum,rows,column,matrix);

}

private void FindTheTotalSum(int i, int j, int sum,int rows,int column,int[][] arr) {

if((i==column-1)&&(j==rows-1)){
System.out.println(sum+” sum of the path”);
}
sum = sum + arr[j][i];
if(i<column-1){
FindTheTotalSum(i+1, j, sum, rows, column,arr);
}
if(j<rows-1){
FindTheTotalSum(i, j+1, sum, rows, column,arr);
}

}