take care of our micro services
TRANSCRIPT
Let's take care of our micro-services
Samuel RozeInviqa
twitter.com/samuelrozegithub.com/sroze
(micro)services
Monolith costs a lot...(only) on the long run !
Microservices are flexible
but introduces complexity!
Key points» Organisation
» Deployment pipeline
» Monitoring & debugging
» Fault tolerance
Key pointsOrganisation
» In the teamsSpotify's squads: the team knows about their services
» Between the teamsResponsibility boundaries, communication, shared goals
Key pointsDeployment pipeline
» New servicesCreate new services within hours
» Continuous DeliverySmall and fast deployments
» Delivery as a ServiceThe teams can change the technology stack themselves
Key pointsMonitoring and debugging
» Pro-active monitoringhealth-checks
» Active error logging and altertingknow what is going on
» Debugging after incidenttracing between services
Key pointsFault tolerance
» Perfection, hopes or embracing faultsBecause that will happen
» ArchitectureA server dies
» ApplicationA service is down or throwing exceptions
Key points, again» Organisation
» Deployment pipeline
» Monitoring & debugging
» Fault tolerance
Environments
Fault tolerance
Tolerance github.com/Tolerance/Tolerance
tolerance.io
ToleranceOperations
Take something that can fail...$comments = $client->getLastComments();
Wrap into an Operationuse Tolerance\Operation\Callback;
$operation = new Callback(function() use ($client) { return $client->getLastComments();});
Run the operation$comments = $runner->run($operation);
Be fault tolerantby decorating the operation
runners
Retry
$waitStrategy = new CountLimited( new ExponentialBackOff( new SleepWaiter(), 1 ), 10);
$runner = new RetryOperationRunner( $decoratedRunner, $waitStrategy);
Fallback
$staticResultFactory = new StaticResultFactory([]);
$runner = new FallbackOperationRunner( $decoratedRunner, $staticResultFactory);
// ...$messages = $runner->run($operation);
Other operation runners...
Rate limiting
$rateLimit = new LeakyBucket( new InMemoryStorage(), new TimeRate(10, TimeRate::PER_SECOND));
$runner = new RateLimitedOperationRunner( $decoratedRunner, $rateLimit, new SleepWaiter());
Buffered (ie postponed runs)
$buffer = new InMemoryOperationBuffer();$bufferedRunner = new BufferedOperationRunner($runner, $buffer);
// Run operations$bufferedRunner->run($firstOperation);$bufferedRunner->run($secondOperation);
// ...// ...
$results = $bufferedRunner->runBufferedOperations();
AppKernel.phpnew Tolerance\Bridge\Symfony\Bundle
\ToleranceBundle();
Get runners from YAML
tolerance: operation_runners: default: retry: # ... callback: # ... buffered: # ... fallback: # ...
Buffered runner
A lot of operations don't have to be executed just now.
$runner->run(new Callback(function() { $this->pushMyBusinessMetricToElasticSearch();}));
» Run operations on kernel.terminate event
AOPAspect Oriented Programming
AOP
tolerance: aop: ~
Wrap your services into operationsjust by using a tolerance.operation_wrapper tag
<services> <service id="app.comments_client" class="App\Comments\HttpClient">
<tag name="tolerance.operation_wrapper" methods="getLastComments" runner="tolerance.operation_runner.default" />
</service></services>
Use your service as usual
$comments = $this->client->getLastComments();
Tolerance MessageProfile
MessageProfile
tolerance: message_profile: enabled: true storage: neo4j: neo4j_client_service_id
current_peer: service: "My service" environment: %kernel.environment% version: 12345
MessageProfileIntegrations
» Guzzle
» Monolog
» RabbitMqBundle
» HttpFoundation
» PSR-7
Thank you!@samuelroze
https://github.com/Tolerance/Tolerance
https://joind.in/talk/2f75b