Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect separate microservice applications?

I am building huge application using microservices architecture. The application will consist of multiple backend microservices (deployed on multiple cloud instances), some of which I would like to connect using rest apis in order to pass data between them.

The application will also expose public api for third parties, but the above mentioned endpoints should be restricted ONLY to other microservices within the same application creating some kind of a private network.

So, my question is:

How to achieve that restricted api access to other microservices within the same application?

If there are better ways to connect microservices than using http transport layer, please mention them.

Please keep the answers server/language agnostic if possible.

Thanks.

like image 230
Patryk Avatar asked Feb 04 '15 10:02

Patryk


1 Answers

Yeah easy. Each client of a micro service has an API key. Micro services only accept requests from clients with a valid API Key.

Also, its good to know that REST is simply a protocol that allows communication between bounded contexts.

It doesn't have to be over HTTP. The requirement is that it has a uniform interface (this is why HTTP is used with its PUT, POST, GET, DELETE... methods) and that it is stateless (all state being transferred through a URI).

So if all your micro services run on the same box, all you need to do is something like this:

class SomeClass implements RestfulMethods {

    public function get(params){ // return something}
    public function post(params){ // add something}
    public function put(params){ // update something}
    public function delete(params){ // delete something}
}

Micro services then communicated by interacting with the RestfulMethod implementations of other services.

But if your micorservices are on different machines, its probably best to use HTTP as the transport mechanism.

like image 92
GWed Avatar answered Sep 24 '22 23:09

GWed