Surviving service distribution

99 problems but a service ain't one

Discovery

API

Docs

Solution you need

API

Consisten API

  • Agree on error codes
  • Agree on presenting data
  • Create npm/gem for parsing/generating

Error codes



{
   "errorCode": "formValidationsFailed",
   "message": "Form validations failed",
   "params": {
     "name": "blank",
     "password": "too_weak",
   },
 }




//------
- No 422 code only 400
- Register to airbreak only 500
- single list of global error codes 
- single list of params error codes
- params hash is always 1 to 1 binded to passed params
- single error per param
- any error which is not caused by wrong request (resource, auth, params) but failure of Core or service should return 500
- human descriptive messages should be provided accurate to context eg:
    + AuthToken already expired
    + Only mobile number allowed

Data prestntation

  • Pagination
  • Metadata
  • Entity reference 
{
  "meta": {
    "pagination": {
        "next": "http://example.com/cursorsNext",
        "prev": "http://example.com/cursorsPrev",
  },
  "data": [
    {
      "id": "3",
      "link": "http://old-better-klara.com/message/3",
      "title": "DATA",
      "body": "DATA",
      "patient_link": "http://old-better-klara.com/patients/1234",
    }
  ],
}

Global NPM/GEM

  • Parses error codes
  • Provides way to return data/error codes
  • If shared between services
  • Service can have own GEM/NPM which is thin wrapper

Docs

  • Create boilerplate for lambda service
  • Each service have docs with endpoints
  • Docs with possible responses
  • Naming convention 
  • Is Readme enough?
  • Should we have centralized wiki?
  • How do we write down API docs?

Discovery

PRODUCTION_TOAST_MAKING_SERVICE_URL="http://someurl"
PRODUCTION_BAKING_SERVICE_URL="http://test"
PRODUCTION_DRUG_DEALER_URL="http://sasdas"
PRODUCTION_SAMPLE_URL="http://dasdas"
PRODUCTION_OTHER_URL="http://asdas"
PRODUCTION_YOUR_MUM_URL="http://asfasfas"
PRODUCTION_SERVICE_WHICH_IS_ACTUALY_USEFULL="http://wrong-outdated-url"

STAGING_TOAST_MAKING_SERVICE_URL="http://someurl"
STAGING_BAKING_SERVICE_URL="http://test"
STAGING_DRUG_DEALER_URL="http://sasdas"
STAGING_SAMPLE_URL="http://dasdas"
STAGING_OTHER_URL="http://asdas"
STAGING_YOUR_MUM_URL="http://asfasfas"
STAGING_SERVICE_WHICH_IS_ACTUALY_USEFULL="http://wrong-outdated-url"

ENV

Possible solutions

  • Consul
  • Zookeeper
  • Etcd

 

But it's really complex

Let's extend Etcd

  • HTTP server
  • Every service registers on startup
  • For lambda it's done on deployment
  • Auth with services
  • Possibility to extend with zones 
  • distinguishes ENV 

Services

By Michał Koźmiński