Every single developer heard this say more than one time during his professional career, 'KIS' which means 'Keep It Simple', however with the excessive evolvement of the web computing and the continues rise of the distributed systems, the complexity of the systems architecture increases. Building a server enterprise application which is highly scalable with high and reliable availability in addition to great performance which consists of set of independent deployable oriented services can be achieved by Microservice architecture. This session introduces briefly what is the Microservice Architecture and how to build it using one of the most popular server programming languages which is called Go or Golang.
3. So what is this Microservices is all about?
Microservices Architecture is a software architecture style in which complex applications
are composed of small, independent processes communicating with each other using
language-agnostic APIs.
Switches
Load Balancer
bla bla bla
DB
DB
DB
5. Let’s go “Monolithic”
let us imagine we are building a social network application.
Front End
User Services
Messaging Services
Payment Services
DB
DB
DB
Web
Server
6. Yes, That’s what I am talking about
-Simple to develop
-Simple to deploy
-Simple to scale
7. , HOWEVER What if, the application get’s bigger and
bigger and the team gets also bigger and bigger.
You might run into these problems:
- Huge applications can be a boogieman specially for new
developers.
- Overloaded web containers.
- Continuous deployment is difficult.
- Requires a long-term commitment to a technology stack.
- Scaling the application can be difficult.
9. Enter Microservices Architecture
- Split your application into independent components based on the
functionality of each one of them.
- Find a protocol to make those services interact with each other whether
in synchronous way or in asynchronous way.
- Remember, each service is totally independent in order to be decoupled
from other services, so each one of them should have it’s own database.
- Consistency between those services can be achieved via having a
database replication mechanism or by applications-level events.
10. Looks a little bit better, right?
User Services
Messaging Services
Payment Services
DB
DB
DB
Front End
11. O.K, those are the benefits of what we have done:
- Each Microservice is relatively small.
- Each service can be deployed independently of other services
- Easier to scale development.
- Improved fault isolation.
- Each service can be developed and deployed independently.
- Eliminates any long-term commitment to a technology stack.
13. Implementing Microservice Architecture using Go
The powerful net/http package lets you write performant web services in a very
quick way.
Basically you want to have many independent worker applications that are
running separately, each with their own responsibility of doing certain tasks.
In real world scenarios you are going to have hundreds of applications running.
You want to talk with them securely (and also authenticated).
You can implement your own MS architecture, using the core package of Go
without looking on what’s already out there.
One of the most impressive packages which helps you building your
infrastructure of your MS architecture is Kite.
15. You asked for it, and I listend ;)
First let me show you a Kite in the most simple form:
Here we just created a kite with the name first and version 1.0.0. The Run() method
is running a server, which is blocking (just like http.Serve).
This kite is now capable of receiving requests.
Because no port number is assigned the OS has picked one for us automatically.
16. Writing a kite
Let us assign a port now, so we can connect to it from another kite (otherwise you
need to pick the assigned URL from the logs).
To change the configuration of a Kite, such as Port number, the properties (such
as Environment, Region, etc… you’ll need to modify the Config fields:
The configuration values can be also overridden via environment variables if
needed.
17. Let us create a second kite to talk with the first kite:
The response of should be something like this:
18. Adding some methods to make things a little bit interesting
Let us add our first custom method. This simple method is going to accept a
name and return a welcome message. The name of the method will be
“sayHello”.
To assign a function to a method just be sure it’s satisfies the kite.Handler
interface (http://godoc.org/github.com/koding/kite#Handler):
19. Let’s call it via our “second” kite:
As you see the only thing that has changed is the method call. When we call the
“sayHello” method we also send the name “Marco Reus” with as an arguments.
You can send any JSON compatible Go type.
21. “Dude!! Where is my car?? ”, Service Discovery
To be discovered by others they need to know your real identity. Basically you
need to be authenticated.
“kitectl” is a handy CLI program which can be used to manage kites easily via
command line. We can use it (via “kitectl register” command) to authenticate
our machine to Kontrol, so every kite running on our host will be authenticated
by default.
Kontrol Configs:
Install Kontrol:
24. That’s it
Thank you and keep up rocking with Go
Moath Qasim
LOVOO GmbH
Resources:
http://microservices.io/patterns/microservices.html
https://godoc.org/github.com/koding/kite
http://blog.gopheracademy.com/birthday-bash-2014/kite-microservice-library/
@MoadQassem