UNPKG

2.65 kBMarkdownView Raw
1# Guidelines
2
3These are things to keep in mind when developing microservices for use with Waif.
4
5## Definition files keep the config out of services.
6
7Each service may ship with zero or more service definition files.
8
9These files map out which services need to be made available, and allow
10you to assign names to each of these services.
11
12## Avoid module.exports, define a REST API instead.
13
14Services are just express apps that export the app instead of calling listen().
15
16By not opening a port, you gain the flexibility of being able to mount the server
17anywhere. This gives Waif the flexibility to mount services intended for the
18network, over unix domain sockets to use as an internal API.
19
20## Doesn't matter where the service is running.
21
22By using REST as the API layer, your services are no longer tied down.
23
24Whether you are calling your service via a socket attached to the same
25process, or a different process, or over tcp connecting to another machine,
26your service should be oblivious to it all.
27
28## Doesn't matter where the service files are on the file system.
29
30Each service may ship with zero or more services of their own.
31
32You could have as many services as you have include files, and they could
33be in relative included files, relatively included submodule directories or
34installed from npm. It's even valid to have a service that just has a definition
35file containing a map of other services (although unlikely).
36
37## Consistent service names mean you can swap out implementations.
38
39There may be multiple implementations for common service types.
40
41Store services are the one that come to mind here. By using a 'store' service
42to interact with our database, we gain the ability to swap out the mongodb
43store service, for a dummy implementation when writing tests.
44
45## Write custom services when you need something more specific.
46
47Services are not meant to be a generalized solution to all problems.
48
49If you have a custom listing that you need to generate from mongo, build a
50simple service to return the JSON for you. You can include it in the service
51you are building it for's codebase and just use it internally. You still
52benefit from increased testability, reduced complexity and the ability
53to scale it out when you finally need to one day.
54
55## Populating credentials and configuration are out of scope.
56
57This is a problem for the form of automated deployment you are using.
58
59Since running many services comes with an increase in deployment issues,
60you will need to figure out what works for service discovery for you.
61
62May I suggest [Longshoreman](http://longshoreman.io)?