Development Guidelines
Development Languages & methodology
12 factor App Methodology
The Twelve Factor Apps:
A modern methodology for building software-as-a-service apps
Every microservice development MUST adhere to the 12 factor apps methodology.
Microservices development MUST comply to each one of the 12 factors defined in the methodology
Polyglot Microservices
Remember this quote when you are choosing a framework:
"It's not the arrow, but the archer"
Microservices MUST be developed using: Python, PHP or Javascript. Any other language development MUST be validated first.
It is RECOMMENDED to use language specific microframeworks to speed-up development such as:
It is NOT RECOMMENDED to use a all-inclusive framework (Laravel, Django, SailsJS, etc) to develop microservices. They add unnecessary fat to a project that usually translates in code complexity. Remember the YAGNI principle.
Testing Approach & Automated testing
Microservices SHOULD be implemented using automated testing.
It IS RECOMMENDED to adhere to Test Driven Design (TDD) practices.
It is RECOMMENDED to adhere to a Tests First approach.
Logging
Logging best practices
A great reference of the 13 best practices you should know when logging.
Microservices MUST treat logs as an event stream. You MUST NOT create log files.
English MUST be used as the default language in logs.
Each Microservice MUST write its event stream to stdout. This allows the logs to be aggregated in production environment and be treated as a single event stream.
In Development, the programmer SHOULD view this stream in the foreground of the terminal to observe the app’s behavior (if needed).
It is RECOMMENDED to use open-source libraries to stream logs and don't reinvent the wheel.
You SHOULD always log at the proper level.
You MUST NOT log sensitive information under any circumstances.
A Microservice MUST NOT log at a debug-level in a production environment.
Events Publishing and Consumption.
Each Microservice MUST declare and configure (via code) its own queue to publish and receive events. Remember the "dumb pipes, smart endpoints" principle.
The event consumption MUST be handled by an separate process (usually a CLI command) running on the background.
It is RECOMMENDED that the event consumption is an infinite respawning process. This allows the service to handle any infrastructure issue and alert accordingly.
Processors
It is RECOMMENDED to bind a unique processor for each type of event the microservice consumes. Usually frameworks allow this type of configuration via a Service Provider Pattern or similar.
Examples
| mezzio/mezzio src/App/ConfigProvider.php | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
| app/queue/event_type_delegate_processor.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
If a microservice gets a message delivery of a type it cannot handle, it is RECOMMENDED to log such events to make troubleshooting easier.
The same way; If a consumer gets a delivery of a payload with errors, it is RECOMMENDED to log this data and log/alert accordingly.
Remember:
"Design for failure, and nothing will fail"
The processors MUST return an ACK or a REJECT depending of the delivery they receive. Generally client libraries can handle this automatically.