Whar are microservices and microservices architecture (MSA) How we reach them? Are they the same or SoA or not? When to use them? What are the key characteristics?
Slides of my talk given in #Gapand2017 in Andorra
5. SOA
• Services have explicit
boundaries
• Services are autonomous
• Services share schema and
contract, not classes
• Services interoperate based
on policy
“Four SoA Tenets” by Don Box
• OASIS Web Services
• WS-*
• SOAP
• Enterprise Service Bus (ESB)
• WebSphere ESB
• BizTalk
• Oracle ESB
• …
8. Microservices
The term "Microservice Architecture" has sprung up over the last few years to
describe a particular way of designing software applications as suites of
independently deployable services. While there is no precise definition of this
architectural style, there are certain common characteristics around organization
around business capability, automated deployment, intelligence in the endpoints,
and decentralized control of languages and data.
https://martinfowler.com/articles/microservices.html
Microservices - also known as the microservice
architecture - is an architectural style that structures an
application as a collection of loosely coupled services,
which implement business capabilities. The microservice
architecture enables the continuous delivery/deployment
of large, complex applications. It also enables an
organization to evolve its technology stack.
9. SOA vs Microservices
SOA Microservicios
Services are generally big Services are generally small
ESB centric role Usually no need for ESB
Favours orchestration over coreography Favours coreography over orquestration
Share as much as possible Share as Little as posible
OASIS WS-*, SOAP, XML, HTTP, … REST, HTTP, …
Who cares about SOA now? Everybody talks about Microservices!
Just one comparison…
But, the reality is…
12. SOAP vs REST
• Heavy message format: XML
and <soap:Envelope> schema
• RPC based: service -> method
(i.e. doctorSvc->GetAllPatients)
• Uses HTTP merely as transport
protocol. Can use other
transports.
• Small messages. No format
assumed
• Resource based (i.e.
/doctors/<id>/patients
• Embraces HTTP semantics: use
HTTP verbs and return codes
13. Orchestration
• Main logic business belongs to a
single central service (the
orchestrator)
• Central service calls other services
and combines its results
• Typical example: BPEL process
15. The 8 key aspects of Microservices (by
Fowler)
1. Componentization via Services
2. Organized around Business Capabilities
3. Products not Projects
4. Smart endpoints and dumb pipes
5. Decentralized Governance
6. Decentralized Data Management
7. Infrastructure Automation
8. Design for failure
https://martinfowler.com/articles/microservices.html
16. The 7 sins of Microservices
• LUST: Using the latest & greatest tech
• GLUTTONY: Excessive communication protocols
• GREED: All your Service are belong to us
• SLOTH: Creating a distributed monolith
• WRATH: Blowing up when bad things happen
• ENVY: The shared single domain fallacy
• PRIDE: Testing in the world of transcience
https://opencredo.com/the-seven-deadly-sins-of-microservices-redux/
17. LUST
• Do not believe that using the latest
tech will solve all your problems
• Docker, k8s, Terraform, Swarm are
great technologies
• But sometimes the right choice is to
pick some old and boring techs
18. GLUTTONY
• HTTP, Protobuff, AMQP, 0MQ,
gRPC, MQTT, …
• All are great communication
protocols…
• …But not all together!
• Choose one synchronous
protocol…
• … And an asynchronous one
19. GREED
• Organization needs to adapt a
“microservices culture”
• Each microservice belongs to
specific team
• Deployment, technologies & tools,
processes… are team
responsabilities
20. SLOTH
• If you don’t change your mind and
develop each microservice with
using same patterns and decisions
used to create monoliths
• You’ll finish not having
microservices at all. Instead...
• You’ll have a set of microservices
that can’t be deployed and updated
independently
21. WRATH
• Failure happens all of time
• Must embrace DevOps mentality of
shared understanding and
responsibility
• Rapid provisioning, monitoring and
deployment are mandatory pre-
requisites
22. ENVY
• Using a Shared Single Domain is
OK when developing a monolith
• In microservices is better to follow
the DDD concept of ‘bounded
context’ to encapsulate better our
services
• Anyway: there is no rule. Don’t
assume that one bounded context
== one microservice
23. PRIDE
• Testing microservices is often
harder (or much harder) than
testing a monolith
• Test as much as you can in your
CI/CD pipelines
• Unit tests, integration tests,
component tests, end-to-end
tests. Automate them all.
25. I - Codebase
• One codebase, many deploys
• If there is more than one
codebase, it is not an app, it is a
distributed system
26. II - Dependencies
• Explicity declare and isolate dependencies
• 12 factor app never relies on the existence of “system-wide” packages
• All dependencies are declared by the app…
• … and a dependency isolation tool is required also
27. III - Config
• Store config in the environment
• Configuration vary between deploys. So can’t be part of the app
• Try to avoid config files, and never store them to repo
• Store configuration in environment variables
28. IV – Backing services
• A backing Service is any external Service consumed by the app
(database, rabbitmq, external mail service,…)
• App must make not distinction between local and 3rd party backing
services
• All backing services are just attached resources that can be accessed
through an URI
• Any backing Service can be changed from local to 3rd party at any
time, only changing configuration
29. V – Build, Release, Run
• Strictly separate the build & run stages
• A codebase is transformed to a deploy through 3 stages
• Build stage: Creating an executable from source code
• Release stage: Deploying the executable to specific environment and apply
config
• Run stage: Starts the app by starting specific executables on the environment
• These 3 stages must be completely isolaged (i. e. can’t change the
code during run or release stages)
30. VI - Processes
• Execute the app as one or more stateless processes
• Any app is stateless and share nothing. Any state must be stored in a
stateful backing Service
• Using local storage and/or memory is OK, only if it used as a cache in
a single request lifetime
• Sticky sessions are (of course) a violation of 12 factor apps
31. VII – Port binding
• Expose Services via port binding
• A 12 factor app is completely self-contained
• No runtime injection of any webserver or similar is allowed
• App expose its functionality using a configurable port
32. VIII - Concurrency
• Scale out via process model
• In 12 factor apps process is a 1st class citizen
• Scale using more processes, instead of any other way (like threads)
• As 12 factor apps are stateless and share nothing, concurrency and
scale using processes is a safe and simple operation
33. IX - Disposability
• Maximize robustness with fast startup and graceful shutdown
• 12 factor apps are disposable: can be stopped at any momento
• App must shutdown gracefully at SIGTERM
• App should be robust when a sudden death happen (i. e. hardware
failure)
34. X – Dev / prod parity
• Keep development, staging, and production as similar as possible
• App must be designed for Continuous deployment in mind: gap
between prod and dev must be as small as posible
• Code authors are code deployers. No “deployment team”
35. XI - Logs
• Treat logs as event streams
• A twelve-factor app never concerns itself with routing or storage of its
output stream
• App never manages its logfiles: just log to the stream
• Environment maps the stream wherever appropiate
36. XII – Admin processes
• Run admin/management tasks as one-off processes
• One-off admin processes should be run in an identical environment as
the regular long-running processes of the app.
• Admin code must ship with application code to avoid synchronization
issues.
39. Microservices are not a free lunch!
• Significant Operations Overhead
• Substantial DevOps Skills Required
• Implicit interfaces management
• Duplication Of Effort
• Distributed System Complexity
• Asynchronicity Is Difficult!
• Testability Challenges
40. So… when to use them?
• If your organization has a strong devops culture
• Microservices allow to break a very big monolith in small pieces. Each
piece can be managed by one pizza team.
• Microservices biggest advantage is agility: you can update, test and
deploy each microservice in an independent way.
41. Agility in Microservices
• Amazon is a heavy user of microservices
• A single shop product use case can interact with 100+ microservices
• Amazon deploy to production…
• Once each 11 hours
42. Agility in Microservices
• Amazon is a heavy user of microservices
• A single shop product use case can interact with 100+ microservices
• Amazon deploy to production…
• Once each 11 hours minutes
43. Agility in Microservices
• Amazon is a heavy user of microservices
• A single shop product use case can interact with 100+ microservices
• Amazon deploy to production…
• Once each 11 hours minutes seconds
44. Agility in Microservices
• NEVER try to use microservices if the organization do not have an
strong Devops culture
• NEVER try to use microservices if a CI/CD pipeline is not established
• Doing Microservices is harder then doing Monoliths. Only
organizations that do monoliths well have a chance to do
microservices well.
45. So…
• Use Microservices if really need them
• Don’t use them only because Amazon and Netflix do (probably your
problems and Amazon problems are not the same).
• Remember: There are not silver bullets
46. Finally:
Serverless
• Serverless means that you don’t
need to bother about server
management
• A step forward than PaaS
• Services are exposed as functions
(FaaS) which are very-micro
services!
• Scale per invocation, not per server
• More on this GAPAND at 11:30 by
@adiazcan & @shmancebo ;-)