Tuesday, March 28, 2017

Microservices Architecture



Microservices Architecture


The term "Microservice Architecture" has come into the picture over the last few years. These days all most all are talking about the microservices. But what is a microservice really..?? why we need it..??and when we need microservices..??

Let see first what is microservice in a simple manner using an example..

what is a Microservice.??

simply, microservices architecture is when you separate your application into smaller applications (we will call them services) that work together.


Asssume that a developing team has developed a large application (ex: online education app) where all the services (ex: login service, registration services,  student service, course service... ) have put inside one data service ( This is what we called as Monolithic Architecture).

In microservices what we do is we breakdown this large application into smaller applications as separate services (login microservice , student microservice , course microservices...). Each microservice act  as a separate end point. In a technical way it describes a particular way of designing software applications as suites of independently deployable services in different servers.

NOTE :
In Monolithic Architecture all services are composed inside one data service rather than containing architecturally separate services.

let see what is the different between monolithic and microservices...























As you see in above picture in Monolithic there is only one service that serves everything and it is hosted on one server and it is hard to scale.

But in Microservies it has different services for each functionallity and we hosted each microservice on different server and it is easy to scale.

If one microservice needs data from some other microservice this communication doing using API which are sent JSON messages.

Why we say that scaling is hard in monolithic and easy in microservices..??

Assume you are using monolithic architecture to develop your application and one service only getting lot of requests from client. Can you scale up only one service or a function in your application then..?? No..since you have put all services into one single process you could not able to scale up one specific function there. But In microservices easily we can scale up one specific service to handle lot of requests coming into it.

I hope now you have the basic idea of microservices.





Monday, March 20, 2017

Version Control Systems (VCS)

Version Controlling

Didn't you ever struggle when you were trying to integrate everyone's files together while working on group projects with your colleagues.Was it easy for you all..??Is it worked smoothly once after  you merged your files..??I guess most of you will say Nooo.. just like me.

But there is a way that you can integrate your project in a proper manner without making files integration conflicts.

But How...??

Using a Version Control System easily you can avoid integration issues.

Now What is this Version Control System..??

Simply, version control system records the changes you make to your project's files , documents, programs, and other information stored as computer files over time. so that you can recall specific versions later.

This is what version control is about. It's really as simple as it sounds.

Do you know the amazing part of VCS...??

  • It allows to revert files back to a previous state.
  • Can revert the entire project back to a previous state.
  •  Also can compare the changes over time.
  • Can see who last modified something that might be causing a problem.


Popular examples for VCS

  • Github
  • Bitbucket
  • GitLab
  • Mercurial
  • Bazaar

Following links are good interactive demos for learning git.
The fundamentals are found in [1] and advanced branching demo is in [2].
[1] https://try.github.io

Distributed vs Centralized


There are many version control systems out there.Mainly we are divided version control systems into two groups.

1. Centralize
2. Distributed” (Decentralized)

First let's see what is the difference between Centralized and Distributed (Decentralized) version control systems.

Centralized version control systems are based on the idea that there is only a single “central” copy of the project  on a server and programmers will “commit” their changes to this central copy.

“Committing” a change simply means recording the change in the central system. Other programmers can then see this change. They can also pull down the change, and the version control tool will automatically update the contents of any files that were changed.Programmers no longer have to keep many copies of files on their hard drives manually, because the version control tool can talk to the central copy and retrieve any version they need

Distributed version control systems (DVCS) do not  rely on a central server to store all the versions of a project’s files. Instead, every developer “clones” a copy of a repository and has the full history of the project on their own hard drive. This copy (or “clone”) has all of the metadata of the original.

The most popular DVCS are Github , Bitbucket ,Mercurial and Bazaar.

I think you got a basic idea of what is version controlling and why we use version controlling..There are few terminologies we need to know when using a version control system for our project. From the provided link[3] below you can get familiar with those  terminologies.

Sunday, March 12, 2017

Diamond Problem in Java

Have you ever  heard about Diamond Problem in java...♦♦???

Yes I'm sure you are ,  if you have ever come across with Object Oriented Concepts  applying in Java. Consideration of the Diamond Problem comes with one of the popular concepts of OOP which is called as the "Inheritance" in Java.

Don't worry if you are new to this and never heard about Diamond Problem. Let's start now..

What is Diamond Problem?

Diamond Problem is sometimes referred as the "Deadly Diamond of Death".

Simply it is an ambiguity that arises when two classes (class B , class C) inherit from a class (class A) and another class (class D) inherits from both B and C.

Have a look at this example if you still didn't get it..


Let's assume that Super class A is an abstract class and class B ,C and D are concrete classes.

Note:
Abstract class :  Base class or a Super class where only declared abstract methods and which does not provide implementations for all of its methods.
Concrete class : Derived class that provides the basic implementations for all of the methods that are not already implemented in the super class.

Here the ambiguity arises in class D when it tries to call Close() method. The compiler doesn't know from which class does it inherit as shown in the figure.

This is a serious problem for some other popular OOP languages like C++ that allows multiple inheritance while java doesn't allow multiple inheritance in classes.

Note:
Multiple Inheritance : Where class can inherit from more than one class

Consider the following situation related to above example.

Class_A.java

Class_A.java
Class_B.java




Class_C.java


Now let's assume Class_D implementation happens as below and it's extending both Class_B and Class_C.

Class_D.java




Here Class_D inherits from both Class_B and Class_C and both classes contain Close() method with different implementations.

In Class_D Test() method call to super class Close() method and this is the place where ambiguity occurred. Because compiler doesn't know which super class method to execute. This referred as diamond problem in Java and this is the main reason why java doesn't support multiple inheritance in classes.

How to Overcome Diamond Problem ?

To overcome this issue Java proposed the solution as Multiple Inheritance in Interface where a single interface can extend multiple interfaces.

Interface_A.java


Interface_B.java

Interface_C.java

Interface_D.java



This is perfectly fine because interfaces declare the methods and actual implementation will be done by concrete classes implementing the interfaces.So there is no possibility of having any kind of ambiguity in multiple inheritance in Java Interfaces.

That's why Java class can implements multiple inheritance like below,



Note: 
Here Class_D must implement the Close() method.If not compiler gives an error by saying you must implement the Close() method at Class_D.