In contrast to the monolithic applications, microservices approach split business functionality to independent external parts, implemented with individual services (from few to hundreds).
Following aspects are essential for implementation of microservices:
- API Gateway
- API Management
- Service registry and discovery
- Database separation and synchronisation (MDM – Master Data Management)
- Service balancing
- Data transfer format
- Automatisation of deployment
Routes and filters requests from external consumer to services.
API gateway can create multiple APIs – to support multiple platforms.
The process of publishing, documenting and overseeing APIs in a secure, scalable environment.
Trace service availability.
Collect, process and present logs from services and infrastructure. Provide efficient access to service activity.
E.g. solution known as “ELK”:
- Elasticsearch – search and analyse data
- Logstash – collect and parse data from machines
- Kibana – explore and visualize data
Service registry and discovery
Access of consumer to services and service instances when endpoints can be dynamic, recoverable or balanced.
Database separation and synchronisation (MDM – Master Data Management)
Services should not have dependencies or coupling over common database. instead – service need its database with specific scope. Common or root data need to be managed/synced/replicated with MDM – to keep consistency and constraints.
Multiple instances of one service can/should be automatically started when performance drops and shut down when resources not used.
Requests for operations and data transferring with asynchronous messages. Messages can use pools of queues. Message IDs can be used to specify the request-respond relation.
Data transfer format
Data and objects can be transferred between consumer and services with different formats:
pros: human-readable, specific data/fragment can be extracted by path
cons: large size
pros: human-readable, supported by web-services, WCF and many other web-technologies
cons: large size, limited types
cons: large size, typeless
Thrift (Apache), Protobuf (Google), Avro (Microsoft)
pros: small size (build-in binary serialization), have types, support of many languages, supports versioning
cons: required resources for compression, not human-readable
Interface if a service should not be changed if it breaks consumer application.
E.g.: methods should not be removed, its signatures should remain the same, fields of DTO objects should not be removed or changed. But new methods can be added as well as fields in DTO objects.
When breaking changes are introduced to the service – a new version of it is published with another endpoint, the old version remain available while all consumers do not adopt the new version (then this obsolete version is removed).
Automatisation of deployment
Microservices supposed to be as fractional as reasonable possible. Amount of services with different versions can grow rapidly. Deployment and management of such infrastructure is expensive without proper automatisation.
Robust messaging for applications
Eureka is a REST based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers.
Service discovery, health check, key-value store
ZooKeeper is an Apache project and provides a distributed, eventually consistent hierarchical configuration store. Service register.
Service Fabric is a distributed systems platform to package, deploy, and manage scalable and reliable microservices – in many environments, including Azure or on premises, on Windows Server or on Linux.
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications.
Criticism, lesson learned, anti-patterns, drawbacks
- Service should be as independent and complete as possible – no logical layers outside, common components or common database.
- No or minimum of manual configuration or deployment.
- Service should not be developed by horizontal teams – one team is responsible for all layers of the service (to avoid dependencies and impediments).
- System, where application(s) depend on an external infrastructure, has many places to break: service registry and discovery, consistency of caches, maintenance of multiple databases and synchronisation MDM to keep consistency, complex deployment procedure, messaging performance and availability, service-balancer.
Caching improves performance reducing amount or requests to databases and other services. Keeping cache consistent and up-to-date is critical and challenging task.
RabbitMQ QOS vs. Competing Consumers
Microservices with C# and RabbitMQ
https://auth0.com/blog/an-introduction-to-microservices-part-1 (part 2 and 3)
Supports C# within version 3.0