Giter Club home page Giter Club logo

node-tcp-ops's Introduction

node-tcp-ops

A proposal for a fast, resilient and scalable service architecture. No dependencies.

requirements

  • scalable on the fly
  • no inter-service dependencies
  • no dependency on startup order
  • automagic reconnection

implementation

  • http-client (like a browser)
  • http-server and tcp-client (api)
  • tcp-server (services)

The browser calls the api which calls service x which responds and the api relays data back to the client. Ports: api http/5001, people tcp/5002, pets tcp/5003, remote tcp/5004.

Clients connect to services on startup and try to reconnect on any socket end event during runtime. Services ignore socket end events as they can have multiple connections running. Clients exit if unsuccessful at connecting to all services. Services and clients exit and restarts on exceptions.

usage

start the show

$ npm start

api

GET /people # returns people
POST /people?name=<string> # creates person
GET /people/pets?owner=<string> # returns pets by owner
GET /status # check status for all services
GET /hash?text=<string> # get md5 for supplied string from remote api

scale on the fly

$ pm2 scale <app> <n>

make remote service use proxy

$ HTTP_PROXY=http://<host>:<port> pm2 restart remote --update-env

connect directly to service

# one shot
$ echo -ne '{"cmd":"status"}' | nc <host> <port>
# or interactive mode
$ nc <host> <port>
> {"cmd":"status"}

tests

$ npm test

todos

  • do tests
  • add scale up and down to tests
  • remove watcher from tests
  • validate inputs
  • compare bufferSize to payload before write
  • log worker id
  • add remote api service
  • add timeout to remote api calls
  • add basic auth
  • add websockets
  • use TLS
  • deploy somewhere, monitor (w appmetrics or pmx) and run load-cron
  • add support for HTTP_PROXY
  • add message queue for disconnects/restarts like axon
  • try send msg to process or use trigger
  • try nc interactive mode
  • use PM2 watch for dev
  • add handler for service server error, close
  • api polling for connection
  • new service abstraction
  • service exit and api reconnect on socket end
  • catch uncaughtException, print error and exit?
  • run w PM2
  • add middleware to router
  • use --max-memory-restart and --max-restarts
  • service status end point
  • connect to services in parallell
  • use cluster
  • cluster always keep n workers
  • persistant connections between api and services
  • refuse http requests during api reconnection
  • make people own pets
  • use persistant db
  • make a router
  • proper error handling
  • figure out how to make req.pipe(people, { end:false }).pipe(res) work without ending the people stream

node-tcp-ops's People

Contributors

karlpokus avatar

Watchers

James Cloos avatar

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.