Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DDD Sous Pression — DDD FR mai 2019

DDD Sous Pression — DDD FR mai 2019

DDD sous pression: retour d'expérience sur la construction d'un système boursier

Ces derniers mois, nous avons construit en partant de zéro un système de bourse électronique (un exchange). Cette soirée sera l’occasion de revenir sur nos découvertes à la fois en terme technique, mais aussi métier, sur ce type de projet qui présente des contraintes assez rares en termes de performances et de fiabilités, le tout dans un environnement métier souvent mal-compris (et mal aimé).

Nous présenterons comment nous avons cherché à ne pas faire disparaitre le métier sous le poids des micro-optimisations techniques, pour répondre à cette question : est-il possible d’allier haute performance et expression métier, est-ce que le DDD sous pression est possible ?

Arnaud LEMAIRE et Jean-Baptiste DUSSEAUT (LGO Group)

Arnaud LEMAIRE

May 02, 2019
Tweet

More Decks by Arnaud LEMAIRE

Other Decks in Programming

Transcript

  1. DDD sous pression Retour d’expérience sur la construction d’un exchange

    Arnaud LEMAIRE @lilobase Jean Baptiste Dusseaut @bodysplash
  2. C’est quoi un trade ? 1 BUY 2@200 2 SELL

    3@200 1 2 TRADE 2@200 Un ordre
  3. C’est quoi un trade ? 1 BUY 2@200 2 SELL

    3@200 1 2 TRADE 2@200 Un ordre Un trade
  4. C’est quoi un trade ? 1 BUY 2@200 2 SELL

    3@200 1 2 TRADE 2@200 3 BUY 1@200 3 2 TRADE 1@200
  5. Le carnet d’ordre 7 BUY 1@199 2 SELL 3@202 4

    BUY 2@200 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198
  6. Le carnet d’ordre 7 BUY 1@199 2 SELL 3@202 4

    BUY 2@200 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 BUY 2@202 10 BUY 1@198
  7. Le carnet d’ordre 7 BUY 1@199 2 SELL 3@202 4

    BUY 2@200 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 BUY 2@202 10 BUY 1@198 TRADE 2@202
  8. Le carnet d’ordre 7 BUY 1@199 2 SELL 3@202 4

    BUY 2@200 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 BUY 2@202 10 BUY 1@198 contre-ordre TRADE 2@202
  9. Le carnet d’ordre 7 BUY 1@199 2 SELL 3@202 4

    BUY 2@200 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 BUY 2@202 10 BUY 1@198 contre-ordre TRADE 2@202 Niveau de prix
  10. Le carnet d’ordre 2 SELL 1@202 3 SELL 4@203 9

    BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  11. Le carnet d’ordre BUY 2@200 2 SELL 1@202 3 SELL

    4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  12. Le carnet d’ordre BUY 2@200 2 SELL 1@202 3 SELL

    4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  13. Le carnet d’ordre 2 BUY 2@200 BUY 2@200 2 SELL

    1@202 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  14. Le carnet d’ordre 2 BUY 2@200 2 SELL 1@202 3

    SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  15. Le carnet d’ordre 2 BUY 2@200 L’ordre est mis dans

    la file 2 SELL 1@202 3 SELL 4@203 9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  16. L’allocation 2 BUY 2@200 2 SELL 1@202 3 SELL 4@203

    9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 7 BUY 1@199 4 BUY 2@200
  17. L’allocation 2 BUY 2@200 2 SELL 1@202 3 SELL 4@203

    9 BUY 3@199 1 SELL 2@204 6 SELL 3@204 UY 1@199 SELL 2@2 5 BUY 5@198 8 BUY 2@198 10 BUY 1@198 SELL 2@200 7 BUY 1@199 4 BUY 2@200
  18. 1 L’allocation : pro-rata 2 BUY 2@200 SELL 2@200 4

    BUY 2@200 4 1 TRADE 1@200 2 1 TRADE 1@200
  19. 1 L’allocation : pro-rata 2 BUY 2@200 SELL 2@200 4

    BUY 2@200 4 1 TRADE 1@200 2 1 TRADE 1@200
  20. 1 L’allocation : pro-rata 2 BUY 2@200 SELL 2@200 4

    BUY 2@200 4 1 TRADE 1@200 2 1 TRADE 1@200
  21. 1 L’allocation : pro-rata 2 BUY 2@200 SELL 2@200 4

    BUY 2@200 4 1 TRADE 1@200 2 1 TRADE 1@200 2 BUY 1@200 4 BUY 1@200
  22. Un chemin critique qui ne s’arrête pas à l’exécution BUY

    2@200 Et parfois notre utilisateur est vraiment une fonction !
  23. Si on résume 1 million d’ordres par seconde sur un

    seul thread, 24h sur 24 et 7j sur 7 Le tout sans pouvoir paralléliser…
  24. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 2 taches composée de 4 étapes
  25. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 taches composée de 4 étapes
  26. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 2 taches composée de 4 étapes
  27. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 2 taches composée de 4 étapes
  28. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 2 taches composée de 4 étapes
  29. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 2 taches composée de 4 étapes
  30. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 6 2 taches composée de 4 étapes
  31. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 6 7 2 taches composée de 4 étapes
  32. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 6 7 8 2 taches composée de 4 étapes
  33. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 6 7 8 2 taches composée de 4 étapes Sans pipelining : 8 ticks
  34. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 2 taches composée de 4 étapes
  35. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 taches composée de 4 étapes
  36. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 2 taches composée de 4 étapes
  37. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 2 taches composée de 4 étapes
  38. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 2 taches composée de 4 étapes
  39. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 2 taches composée de 4 étapes
  40. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 2 taches composée de 4 étapes Sans pipelining : 5 ticks
  41. Le pipelining Temps Step #1 Step #2 Step #3 Step

    #4 1 2 3 4 5 2 taches composée de 4 étapes Sans pipelining : 5 ticks Parallélisme sans concurrence
  42. Le pipelining private Disruptor<PlatformEvent> createDisruptor() { Disruptor<PlatformEvent> disruptor = new

    Disruptor <>(
 PlatformEvent ::new, bufferSize(), new ThreadFactoryBuilder()
 .setNameFormat("disruptor").build(), ProducerType.MULTI, new BlockingWaitStrategy()); disruptor.handleEventsWith(logger).and(marshaller) .then(business_handler) .then(output); return disruptor; }
  43. Le pipelining private Disruptor<PlatformEvent> createDisruptor() { Disruptor<PlatformEvent> disruptor = new

    Disruptor <>(
 PlatformEvent ::new, bufferSize(), new ThreadFactoryBuilder()
 .setNameFormat("disruptor").build(), ProducerType.MULTI, new BlockingWaitStrategy()); disruptor.handleEventsWith(logger).and(marshaller) .then(business_handler) .then(output); return disruptor; } Architecture LMAX ?
  44. Haute disponibilité Et aussi survivre au reboot, tout simplement Execution

    engine 1 Execution engine 2 Execution engine 3 ? ? ? ?
  45. Execution engine 1 Command sourcing ! Execution engine 2 Execution

    engine 3 Le metier doit etre deterministe
  46. Json, un load tester pour votre GC MTU & taille

    de vos messages Encoding Binaire
  47. Media Driver Sender Conductor Receiver Media Driver Sender Conductor Receiver

    Client Publisher Conductor Subscriber Client Subscriber Conductor Publisher Aeron: Messaging
  48. Aeron Cluster : Raft Media Driver Sender Conductor Receiver Archiving

    Media Driver Consensus module Clustered Service Business logic Snapshot
  49. Projections « lentes » Execution engine 1 Execution engine 2

    Execution engine 3 Consommateur CRC 32 check
  50. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  51. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  52. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  53. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  54. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  55. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  56. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  57. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  58. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  59. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  60. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  61. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  62. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  63. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  64. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  65. Web gateway Web socket gateway AFR Execution Engine Exchange view

    Accounting Internal gateway Accounting import Settlement CA OTS Blockchain / Custody
  66. En réalité il est peu impacté, la performance se construit

    grâce à l’orchestration de celui-ci Mais finalement on parle de DDD ? Et le métier, il est où ?