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