Coder Social home page Coder Social logo

dot-microservices / dot Goto Github PK

View Code? Open in Web Editor NEW
10.0 6.0 0.0 1.72 MB

a minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices

Home Page: http://dot-microservices.js.org/

License: MIT License

JavaScript 100.00%
microservices soa rpc autodiscovery fault-tolerant-microservices microservice-framework microservice-toolkit

dot's Introduction

dot

dot is a minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices. Please see this article to find out more.

Dot Schema

Install

npm i --save node-dot

You can also clone this repository and make use of it yourself.

git clone https://github.com/Dvs-Bilisim/dot.git
cd dot
npm i
npm test

Components

There are 2 simple components:

  • Server : ~100 LOC, extends Base (~50 LOC)
  • Client : ~150 LOC, extends Base (~50 LOC)

Documentation lines are not included to LOC values.

Server will automatically manage routing between client and Service instances. String responses are reserved for errors. If you send a string back, it means that an error occured. Client is for sending requests.

Configuration

Server

  • debug : Debug mode. It's disabled by default.
  • delimiter : Delimiter between service and method names. It's a single dot(.) by default.
  • discover : Parameters for node-discover module. Please see official repository for more information.
  • group : This parameter is for grouping services. If you set a value, client instance connects matched servers only.
  • iface : optional. name of the network interface to get outer ip from
  • port : Start point for port range. If you set server instance looks up for its port starting from this number. It's 8000 by default.
  • secret : Encryption key for auto discovery feature. It's a string "dot" by default.

Client

  • debug : Debug mode. It's disabled by default.
  • delimiter : Delimiter between service and method names. It must be same value in server and client instances. It's a single dot(.) by default.
  • discover : Parameters for node-discover module. Please see official repository for more information.
  • group : This parameter is for grouping services. If you set a value, client instance connects matched servers only.
  • secret : Encryption key for auto discovery feature. It's a string "dot" by default.
  • timeout : Request timeout. Socket communication has auto recovery feature but in some cases you might want to have a timeout option.

Error Types

To have a better understanding on error types, there are a few more things to explain. A service is the name of your Service class in camel-case form and each static function in that class is called method. On client-side, you need to concatenate service name and method with delimiter as path. Default delimiter is a single dot(.). You can configure that by delimeter parameter.

  • INVALID_METHOD : Requested method doesn't exist in your service class
  • INVALID_PATH : Path parameter is not a valid string
  • INVALID_RESPONSE : Service sent an invalid response back
  • INVALID_SERVICE : Requested service doesn't exist
  • LOCKED : Clean shutdown on progress
  • MISSING_METHOD : Method is not a valid string
  • REQUEST_TIMEOUT : Request sent via socket but no response in allowed amount of time
  • SERVICE_TIMEOUT : No service found to send the request in allowed amount of time

Example Server

const Server = require('node-dot').Server;

class SampleService {
    static test(request, reply) {
        reply(request);
    }

    static async test2(request) {
        if (!request) throw new Error('invalid request');
        return request;
    }
}

const server = new Server();
server.addService(SampleService);
server.start();

Example Client

const Client = require('node-dot').Client;

const client = new Client();
client.send('sampleService.test', request, response => {
    console.log(response);
});

Benchmark

Test device specifications.

  • Dell XPS 13
  • Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz 4 Cores
  • 8 GB Ram

First, you should start server instance. Then execute following command:

node tests/benchmark.js

Your results should be similar to following values:

total time spent for 25000 requests is 0.98 seconds
min processing time is 0.20 seconds
max processing time is 0.76 seconds
average processing time is 0.46 seconds

dot's People

Contributors

dependabot[bot] avatar umuplus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dot's Issues

extending to be polyglot

Node.js is at dot's core but I think there are a few ways to extend it to be polyglot.

It's possible to port node-discover project to other programming languages which would be really nice and probably the best way. But this adds complexity to maintenance.
We can sync our zeroconf service discovery state with a Redis server via a master instance and other languages can use Redis for service discovery. That approach has 2 problems. First, that way we can support only polyglot client implementations and all services must be in Node.js Otherwise things would be extremely complicated. We also have to replace axon library with a polyglot library such as ZeroMQ.

There is one more thing that I should also keep in mind, in future I'll add a layer to combine services in different networks (data centers, clouds, etc.) The implementation to support polyglot should never break that layer in any way.

cache plugin

Should we provide a cache mechanism for microservice requests or we should leave it to application layer?

add redis support for service discovery

Most of the cloud platforms don't support broadcast or multicast messages.
Because of that, we need an alternative middle layer as service registry.
This might also help to be polyglot.

clean shutdown

before adding inter-regions communication layer, project needs a solid way for clean shutdown.

client authentication / authorization

Does dot need a layer for auth?

If it does, sockets need to apply auth after being accepted. For that, server instance might provide a method for auth implementation.

Proposal example:

$instance.setAuth((next) => {
// ... auth impl.
next(true); // or next(false);
});

Otherwise, services might apply their own auth implementation in application layer.

network monitor

dot needs a tool for monitoring services. Thus, devops can aware of any change on service existance.

I don't mean availability of services only. Optional traffic visualization would be great!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.