(micro)services avec
Symfony et Tolerance
Samuel Roze
Inviqa / SensioLabs UK
@samuelroze
github.com/sroze
(micro)services
The monolith
Maintenance
très chère
SOA
Microservices
Fléxibilité
Points clés
» Organisation
» Déploiement
» Monitoring
» Résiliance
» Debugging
Points clés
Organisation
» Responsabilité humaine (équipe)
» Responsabilité technique (boudaries)
» Communication humaine (objectifs communs)
» Communication technique (documentation, BC, ...)
Points clés
Déploiement
» Continuous Deployment
» Continuous Delivery
» Simple (Platform.sh, ContinuousPipe.io, ...)
» Scalable (AWS, Google Cloud, ...)
Points clés
Monitoring
» User-end monitoring (NewRelic, Google Analytics, ...)
» Infrastructure monitoring (NewRelic, Sysdig, Datadog, ...)
» Application monitoring (StatsD, ELK, Keen.io, ...)
» Pro-active monitoring
Points clés
» Organisation
» Déploiement
» Monitoring
» Résiliance
» Debugging
Tolerance
 github.com/Tolerance/Tolerance
tolerance.io
 Résiliance
Une opération
$comments = $client->getLastComments();
Une opération
use ToleranceOperationCallback;
$operation = new Callback(function() use ($client) {
return $client->getLastComments();
});
Runner
$comments = $runner->run($operation);
 Résiliance
aux erreurs
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);
Résiliance
aux attaques
Rate limiting
$rateLimit = new LeakyBucket(
new InMemoryStorage(),
new TimeRate(10, TimeRate::PER_SECOND)
);
$runner = new RateLimitedOperationRunner(
$decoratedRunner,
$rateLimit,
new SleepWaiter()
);
D'autres types de
runners...
Buffered
$buffer = new InMemoryOperationBuffer();
$bufferedRunner = new BufferedOperationRunner($runner, $buffer);
// Run operations
$bufferedRunner->run($firstOperation);
$bufferedRunner->run($secondOperation);
// ...
// ...
$results = $bufferedRunner->runBufferedOperations();
Symfony!
AppKernel.php
ToleranceBridgeSymfonyBundleToleranceBundle();
Runners with YAML
tolerance:
operation_runners:
default:
retry:
runner:
callback: ~
waiter:
count_limited:
count: 10
waiter:
exponential_back_off:
exponent: 1
waiter:
sleep: ~
 Buffered terminaison
» Automatically with factory
» Manual runners needs to be tagged
<service
id="app.my_buffered_operation_runner"
class="ToleranceOperationRunnerBufferedOperationRunner">
<!-- Arguments... -->
<tag name="tolerance.operation_runner" />
</service>
 AOP
 AOP
tolerance:
aop: ~
AOP
<services>
<service id="app.comments_client" class="AppCommentsHttpClient">
<tag name="tolerance.operation_wrapper"
methods="getLastComments"
runner="tolerance.operation_runner.default" />
</service>
</services>
AOP
$comments = $this->client->getLastComments();
Debugging
» Sentry
» Tideways
» NewRelic
» Logs "manuels"
» ...
Tolerance
 MessageProfile
MessageProfile
tolerance:
message_profile:
enabled: true
storage:
neo4j: neo4j_client_service_id
current_peer:
service: "My service"
environment: %kernel.environment%
version: 12345
MessageProfile
Integrations
» Guzzle
» Monolog
» RabbitMqBundle
» Symfony
» HttpFoundation
» PSR-7
Merci!
@samuelroze
https://github.com/Tolerance/Tolerance
https://joind.in/event/nouveau-sfpot--lille-le-3103-

(micro)services avec Symfony et Tolerance