SlideShare a Scribd company logo
Microservices – Event Driven Systems
Arnaud Bouchez - Synopse
MICROSERVICES
Event Driven Design
Microservices – Event Driven Systems
• Arnaud Bouchez
– Delphi Expert
• Various solutions (from Vatican to gaming industry)
• IoT solution (RSI)
• Real-time Monitoring solution (LiveMon)
– Open Source
• mORMot (SOA ORM MVC framework)
• SynPDF SynMustache SynDB SynCrypto
– Training and consultancy
• Synopse one-man company
Microservices – Event Driven Systems
Event-Driven Systems
• Using Events?
• Event-Driven Design
• Event-Driven mORMot
Microservices – Event Driven Systems
Using Events?
• Imperative Architecture
– Events are high-level commands
Microservices – Event Driven Systems
Using Events?
• Imperative Architecture
– Events are high-level commands
• Easy modelization into regular code
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
var temp: TTemperature;
begin
temp := TemperatureSensor.GetTemperature;
if temp > Threshold then
RoboValet.FetchDownJacket(Sender);
end;
Microservices – Event Driven Systems
Using Events?
• Imperative Architecture
– State is stored in a main shared DB
– Events are high-level commands
translated into SQL statements
Microservices – Event Driven Systems
Using Events?
• Imperative Architecture
– State is stored in a main shared DB
– Events are high-level commands
translated into SQL statements
• DB-centric approach
• Atomicity is ensured, but history is lost
• DB becomes a bottleneck
Microservices – Event Driven Systems
Using Events?
• Event-Driven Architecture
– Collaboration is done using Events
Microservices – Event Driven Systems
Using Events?
• Event-Driven Architecture
– Collaboration is
done using Events
Just like
VCL/FMX /LCL !
Microservices – Event Driven Systems
Using Events?
• Event-Driven Architecture
– Collaboration is done using Events
– System consists in uncoupled nodes
which could be added or removed on-the-fly
– Nodes publish events, and subscribe to them
– Each node stores the information it needs
– Some API gateways expose state via REST
Microservices – Event Driven Systems
Event-Driven Architecture
• Nodes implemented as services
procedure TZen.Init;
begin
TemperatureSensor.SubscribeToTempChange(OnTempChanged);
end;
procedure TZen.OnTempChanged(NewTemp: TTemperature);
begin
CurrentTemp := NewTemp;
end;
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
begin
if CurrentTemp > Threshold then
RoboValet.NotifyNeedsJacket(Sender);
end;
Microservices – Event Driven Systems
Event-Driven Architecture
– Collaboration is done using Events
Not natural to imperative code (Delphi, C#, Java)
– System consists in uncoupled nodes
Architecture becomes complex
– Nodes publish events, and subscribe to them
May be subject to unexpected loops
– Each node stores the information it needs
Duplicated data, with eventual consistency
Microservices – Event Driven Systems
Event-Driven Architecture
• More complex than imperative code
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
var temp: TTemperature;
begin
temp := TemperatureSensor.GetTemperature;
if temp > Threshold then
RoboValet.FetchDownJacket(Sender);
end;
Microservices – Event Driven Systems
Event-Driven Architecture
• Events may be received for no use
e.g. the following method is always called
procedure TZen.OnTempChanged(NewTemp: TTemperature);
begin
CurrentTemp := NewTemp;
end;
but this value may never be used in
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
begin
if CurrentTemp > Threshold then
RoboValet.NotifyNeedsJacket(Sender);
end;
Microservices – Event Driven Systems
Event-Driven Architecture
• Danger of unexpected infinite loop
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
begin
if CurrentTemp > Threshold then
RoboValet.NotifyNeedsJacket(Sender);
end;
What happens
if RoboValet.NotifyNeedsJacket
triggers (indirectly) TZen.HandleIAmGoingOut ?
Since nodes may be added at any time,
how to prevent it to happen?
Microservices – Event Driven Systems
Event-Driven Architecture
• Danger of unexpected infinite loop
procedure TZen.HandleIAmGoingOut(Sender: TPeople);
begin
if CurrentTemp > Threshold then
RoboValet.NotifyNeedsJacket(Sender);
end;
What happens
if RoboValet.NotifyNeedsJacket
triggers (indirectly) TZen.HandleIAmGoingOut ?
Enter the Event-Driven debugging hell:
actual event process depends on the system it runs on
Microservices – Event Driven Systems
Event-Driven Architecture
• So, when to use it?
– Your are modeling evolving information
• e.g. scale to a lot of devices or users
– You need to track changes of state
• A monolithic DB only stores the current state
(via Update) - otherwise it may sink under Inserts
• Event-Sourcing and CQRS (see later)
Microservices – Event Driven Systems
Event-Driven Architecture
• So, when to use it?
– You expect a modular design
• Process not written in stone during compilation
(as in imperative programming): add/enable nodes
to change the system behavior at runtime
• Microservices, SaaS, horizontal scaling
Microservices – Event Driven Systems
Event-Driven Architecture
• So, when to use it?
– You defined a stateless domain
• From state comes complexity,
so DDD usually modelizes a time snapshot
• DDD events are a way to introduce temporality
– Never 100% Event-Driven
• You will eventually define REST API gateways
Microservices – Event Driven Systems
Event-Driven Architecture
• Message Bus
– Most common way to implement Event-Driven
• Cloud, Local or in-house Queues
• Like VCL TApplication.ProcessMessages
– Publish/Subscribe mechanism
• Nodes get only needed information
• Nodes could be added/removed
– Used in conjunction with regular DB and REST
Microservices – Event Driven Systems
Event-Driven Architecture
• Message Bus
Microservices – Event Driven Systems
Event-Driven Architecture
• Peer to peer communication
– Nodes communicate directly between them
• Each node manages its own queue(s)
• Good integration with REST
• Need a centralized catalog service, P2P ZeroMQ,
or convention-over-configuration setup
• As offered by mORMot over WebSockets
Microservices – Event Driven Systems
Event-Driven Architecture
• Event Sourcing
– Business logic is implemented through Events
– Events are persisted, not state
• Play the events to compute a state
• Intermediate states may be cached/persisted
– Events are transmitted, not state
• Publish/Subscribe instead of REST
• Define API gateways for the outer world
Microservices – Event Driven Systems
Event-Driven Architecture
• Event Sourcing
– Business logic is implemented through Events
– Convenient way to define Microservices
• Subscribe to events, to get the information
• Publish events, as result of the process
– Microservices persistence
• Most Microservices will use a regular state storage
• Some Microservices will use Event Sourcing
Microservices – Event Driven Systems
Event-Driven Architecture
• Events and CQRS
– Command Query Responsibility Segregation
• Commands triggers events
• Events are gathered and stored
• State/Events store is uncoupled from Commands
– CQRS follows a non CRUD pattern
• Create Read Update Delete
Microservices – Event Driven Systems
Event-Driven Architecture
• CRUD
DB
Microservices – Event Driven Systems
Event-Driven Architecture
• CQRS
DB
Microservices – Event Driven Systems
Event-Driven mORMot
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services
type
ICalculator = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
/// add two signed 32 bit integers
function Add(n1,n2: integer): integer;
end;
– Defines the contract of the service
– Microservice: should follow SOLID principles
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services
procedure ResolveCalculator(out: ICalculator);
...
function TMyClient.MyAdd(a,b: integer): integer;
var Calculator: ICalculator;
begin
Client.Services.Resolve(ICalculator, Calculator);
result := Calculator.Add(a,b);
end;
– Runtime injection of the actual implementation
• May be in-process, local or remote
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services
var Calculator: ICalculator;
begin
Client.Services.Resolve(ICalculator, Calculator);
result := Calculator.Add(a,b);
end;
– Client is a mORMot TSQLRestClientURI
– Will communicate using JSON over HTTP(S)
Microservices – Event Driven Systems
Event-Driven mORMot
• RESTful Local and Client-Server
– In-process
Stand-alone client, fast server-side access
– Named pipes or Windows messages
Stand-alone client, fast server-side access
– HTTP/1.1 via kernel-mode http.sys API
• Kernel-mode execution, IOCP driven, https – Windows specific
– HTTP/1.1 via OS socket API
• Windows or Linux, using a Thread Pool, https via Reverse Proxy
• Upgradable to WebSockets
Microservices – Event Driven Systems
Event-Driven mORMot
• RESTful Client
TSQLRestServer
TSQLRest
TSQLRestClientURI
TSQLRestClient
Microservices – Event Driven Systems
Event-Driven mORMot
• RESTful Server
TSQLRestServerDB
TSQLRestServer
TSQLRest
TSQLRestServerRemoteDB TSQLRestServerFullMemory
Microservices – Event Driven Systems
Event-Driven mORMot
• RESTful Local and Client-Server
– Needed methods are available at TSQLRest
• REST auto-routing
• JSON high-performance serialization
• Following Liskov Substitution Principle
– Focus on the logic
– Abstract from the plumbing
Microservices – Event Driven Systems
Event-Driven mORMot
• REST/JSON Persistence via ORM/ODM
– Agnostic Storage for Events or State
• ORM over local SQlite3 store
• ORM over remote SQL databases
• ODM over TObjectList
• ODM over MongoDB
Switching from one to another
in a few lines of code, or through settings
Microservices – Event Driven Systems
Event-Driven mORMot
• REST/JSON Persistence via ORM/ODM
– Advanced ORM features
• REST Convention-Over-Configuration routing
• Direct DB-to-JSON serialization (no TDataSet)
• Built-in statement and JSON cache
• Batch (Unit-Of-Work) writes: bulk SQL/NoSQL insert
• SQL logging/timing, real-time replication,
data sharding, remote proxying
Microservices – Event Driven Systems
Event-Driven mORMot
• Cross-platform
– Main mORMot units
• Delphi: Windows x86/x64
Best IDE experience for coding and debugging
• FPC: Windows, MacOS, Android, Linux, BSD
x86/x64, ARM32/AARCH64 (PPC32/PPC64)
• (Cross)Kylix: Linux x86
Microservices – Event Driven Systems
Event-Driven mORMot
• Cross-platform
– Generated client code using Mustache templates
• Delphi: Windows, MacOS, Android, iOS
• FPC: Windows, MacOS, Android, iOS, Linux, …
• (Cross)Kylix: Linux
• SmartMobileStudio: JavaScript Ajax / HTML5
– Featuring almost all framework abilities
• JSON marshalling, security, instance lifetime
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Specify the callback as an interface parameter
• Native way of coding in object pascal
– Real-time push notifications over WebSockets
• Upgraded from a standard HTTP connection
– Peer To Peer communication
• No need of a centralized message bus / server
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Real-time push notifications over WebSockets
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Specify the callback as an interface parameter
ILongWorkCallback = interface(IInvokable)
...
end;
ILongWorkService = interface(IInvokable)
['{09FDFCEF-86E5-4077-80D8-661801A9224A}']
procedure StartWork(const workName: string;
const onFinish: ILongWorkCallback);
function TotalWorkCount: Integer;
end;
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Real-time push notifications over WebSockets
• Once upgraded, communicates using frames
over a bi-directional socket connection
using application-level protocols
• Security, frames gathering, REST emulation
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Real-time push notifications over WebSockets
• Once upgraded, communicates using frames
over a bi-directional socket connection
using application-level protocols
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Security, Frames gathering, REST emulation
• TWebSocketProtocolBinary = SynLZ + AES-256
• Regular blocking methods expecting results
will be emulated like regular REST requests,
with REST security and parameters marshalling
• Non-blocking methods with no result
will be asynchronously sent,
optionally gathered as “jumbo frames”
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Publish/Subscribe Pattern
also known as “Observer”
Publisher
Subscriber 1
Event
Subscriber 2
Event
Subscriber 3
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Beware of “Race Conditions”
• Use critical sections (e.g. TSynLocker)
to protect your shared data on multi-threaded server
• You can gather all non-blocking callback process in a
background thread via TSQLRest.AsynchRedirect
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Beware of “Dead Locks”
• If your callback triggers another method
which shares the same critical section
in another thread, you may block both threads
• You can gather all non-blocking callback process in a
background thread via TSQLRest.AsynchRedirect
Microservices – Event Driven Systems
Event-Driven mORMot
• Interface-based services callbacks
– Sample 31
• Long-Work Push Notification
also known as “Sagas”
• Publish/Subscribe Pattern
also known as “Observer”
Microservices – Event Driven Systems
• Credits
Martin Fowler
https://martinfowler.com
code and samples at
https://synopse.info
Microservices – Event Driven Systems
Event-Driven Systems
• Questions?

More Related Content

PDF
Ekon21 Microservices - SOLID Meets SOA
Arnaud Bouchez
 
PDF
Detecting secrets in code committed to gitlab (in real time)
Chandrapal Badshah
 
PDF
Subversion to Git Migration
Manish Chakravarty
 
PPTX
WebSocket MicroService vs. REST Microservice
Rick Hightower
 
PDF
MySQLバックアップの基本
yoyamasaki
 
PDF
워터폴에서 애자일로의 전환, 그리고 그 지원 시스템 구성 - 투씨드
Atlassian 대한민국
 
PPTX
Introduction to DevOps. Continuous Integration by Myroslav Dmytrus
Binary Studio
 
PPTX
Developing Active-Active Geo-Distributed Apps with Redis
Cihan Biyikoglu
 
Ekon21 Microservices - SOLID Meets SOA
Arnaud Bouchez
 
Detecting secrets in code committed to gitlab (in real time)
Chandrapal Badshah
 
Subversion to Git Migration
Manish Chakravarty
 
WebSocket MicroService vs. REST Microservice
Rick Hightower
 
MySQLバックアップの基本
yoyamasaki
 
워터폴에서 애자일로의 전환, 그리고 그 지원 시스템 구성 - 투씨드
Atlassian 대한민국
 
Introduction to DevOps. Continuous Integration by Myroslav Dmytrus
Binary Studio
 
Developing Active-Active Geo-Distributed Apps with Redis
Cihan Biyikoglu
 

What's hot (20)

PPTX
Git Branching – the battle of the ages
Jasmin Fluri
 
PDF
Pythonでブラウザをいっぱい動かしたい
Kameko Ohmura
 
PDF
우리가 몰랐던 크롬 개발자 도구
Jae Sung Park
 
PPTX
Redis Streams
Redis Labs
 
PDF
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
PDF
How to upgrade like a boss to MySQL 8.0 - PLE19
Alkin Tezuysal
 
PPTX
Chaos Engineering for PCF
VMware Tanzu
 
PDF
MariaDB MaxScale: an Intelligent Database Proxy
Markus Mäkelä
 
PPSX
Apache metron - An Introduction
Baban Gaigole
 
PDF
gRPC Overview
Varun Talwar
 
PDF
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
PDF
OpenSearch.pdf
Abhi Jain
 
PDF
MySQL GTID Concepts, Implementation and troubleshooting
Mydbops
 
PPTX
Giới thiệu tổng quan Agile-Scrum
Tam Pham Minh
 
PDF
Event Sourcing - Greg Young
JAXLondon2014
 
PDF
Introduction To Liquibase
Knoldus Inc.
 
PDF
Faster, better, stronger: The new InnoDB
MariaDB plc
 
PDF
MySQL Parallel Replication by Booking.com
Jean-François Gagné
 
PPTX
Come Fly With Me: Database Migration Patterns with Flyway
Joris Kuipers
 
PDF
PHP unserialization vulnerabilities: What are we missing?
Sam Thomas
 
Git Branching – the battle of the ages
Jasmin Fluri
 
Pythonでブラウザをいっぱい動かしたい
Kameko Ohmura
 
우리가 몰랐던 크롬 개발자 도구
Jae Sung Park
 
Redis Streams
Redis Labs
 
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
How to upgrade like a boss to MySQL 8.0 - PLE19
Alkin Tezuysal
 
Chaos Engineering for PCF
VMware Tanzu
 
MariaDB MaxScale: an Intelligent Database Proxy
Markus Mäkelä
 
Apache metron - An Introduction
Baban Gaigole
 
gRPC Overview
Varun Talwar
 
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
OpenSearch.pdf
Abhi Jain
 
MySQL GTID Concepts, Implementation and troubleshooting
Mydbops
 
Giới thiệu tổng quan Agile-Scrum
Tam Pham Minh
 
Event Sourcing - Greg Young
JAXLondon2014
 
Introduction To Liquibase
Knoldus Inc.
 
Faster, better, stronger: The new InnoDB
MariaDB plc
 
MySQL Parallel Replication by Booking.com
Jean-François Gagné
 
Come Fly With Me: Database Migration Patterns with Flyway
Joris Kuipers
 
PHP unserialization vulnerabilities: What are we missing?
Sam Thomas
 
Ad

Similar to Ekon21 Microservices - Event Driven Design (20)

PDF
Deconstructing Monoliths with Domain Driven Design
VMware Tanzu
 
PDF
Building Event Driven Systems
WSO2
 
PPT
Correlation Architecture
sboray
 
PDF
Patterns of Distributed Application Design
GlobalLogic Ukraine
 
PPTX
Event Driven Microservices architecture
NikhilBarthwal4
 
PPTX
Microservices Architecture
Alessandro Giorgetti
 
PPTX
Let's talk about... Microservices
Alessandro Giorgetti
 
PPTX
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays
 
PPTX
Patterns of Distributed Application Design
Orkhan Gasimov
 
PDF
Lighning Talk: Event-Driven architecture for microservices
Martins Sipenko
 
PDF
1. Why Event-Driven Microservices _ Building Event-Driven Microservices.pdf
RajeevKumarSingh87
 
PPTX
Event mesh APIDays melbourne September 2019
Phil Scanlon
 
PDF
Modernising Change - Lime Point - Confluent - Kong
confluent
 
PPTX
Event-Based API Patterns and Practices
LaunchAny
 
PDF
Design Microservice Architectures the Right Way
C4Media
 
PPTX
Over view of software artitecture
ABDEL RAHMAN KARIM
 
PDF
apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...
apidays
 
PPTX
Introduction to Microservices Patterns
arconsis
 
PPTX
Introduction to Microservices Patterns
Dimosthenis Botsaris
 
PDF
apidays LIVE London 2021 - Getting started with Event-Driven APIs by Hugo Gue...
apidays
 
Deconstructing Monoliths with Domain Driven Design
VMware Tanzu
 
Building Event Driven Systems
WSO2
 
Correlation Architecture
sboray
 
Patterns of Distributed Application Design
GlobalLogic Ukraine
 
Event Driven Microservices architecture
NikhilBarthwal4
 
Microservices Architecture
Alessandro Giorgetti
 
Let's talk about... Microservices
Alessandro Giorgetti
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays
 
Patterns of Distributed Application Design
Orkhan Gasimov
 
Lighning Talk: Event-Driven architecture for microservices
Martins Sipenko
 
1. Why Event-Driven Microservices _ Building Event-Driven Microservices.pdf
RajeevKumarSingh87
 
Event mesh APIDays melbourne September 2019
Phil Scanlon
 
Modernising Change - Lime Point - Confluent - Kong
confluent
 
Event-Based API Patterns and Practices
LaunchAny
 
Design Microservice Architectures the Right Way
C4Media
 
Over view of software artitecture
ABDEL RAHMAN KARIM
 
apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...
apidays
 
Introduction to Microservices Patterns
arconsis
 
Introduction to Microservices Patterns
Dimosthenis Botsaris
 
apidays LIVE London 2021 - Getting started with Event-Driven APIs by Hugo Gue...
apidays
 
Ad

More from Arnaud Bouchez (20)

PDF
mORMot 2 - Pascal Cafe 2025 in Nederlands
Arnaud Bouchez
 
PDF
EKON28 - Beyond Legacy Apps with mORMot 2
Arnaud Bouchez
 
PDF
EKON28 - Winning the 1BRC Challenge In Pascal
Arnaud Bouchez
 
PDF
EKON28 - Diving Into X.509 Certificates with mORMot 2
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez FPC and Lazarus
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez mORMot Gems
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez From RAD to REST and SOA
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez ORM ODM and mORMot
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez From Classes to Interfaces
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez Technical Debt
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez Test Driven Design
Arnaud Bouchez
 
PDF
2024 DAPUG Conference Arnaud Bouchez mORMot as a ToolBox
Arnaud Bouchez
 
PDF
EKON27-FrameworksTuning.pdf
Arnaud Bouchez
 
PDF
EKON27-FrameworksExpressiveness.pdf
Arnaud Bouchez
 
PDF
Ekon25 mORMot 2 Server-Side Notifications
Arnaud Bouchez
 
PDF
Ekon25 mORMot 2 Cryptography
Arnaud Bouchez
 
PDF
Ekon24 from Delphi to AVX2
Arnaud Bouchez
 
PDF
Ekon24 mORMot 2
Arnaud Bouchez
 
PDF
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Arnaud Bouchez
 
PDF
Ekon23 (1) Kingdom-Driven-Design
Arnaud Bouchez
 
mORMot 2 - Pascal Cafe 2025 in Nederlands
Arnaud Bouchez
 
EKON28 - Beyond Legacy Apps with mORMot 2
Arnaud Bouchez
 
EKON28 - Winning the 1BRC Challenge In Pascal
Arnaud Bouchez
 
EKON28 - Diving Into X.509 Certificates with mORMot 2
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez FPC and Lazarus
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez mORMot Gems
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez From RAD to REST and SOA
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez ORM ODM and mORMot
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez From Classes to Interfaces
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez Technical Debt
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez Test Driven Design
Arnaud Bouchez
 
2024 DAPUG Conference Arnaud Bouchez mORMot as a ToolBox
Arnaud Bouchez
 
EKON27-FrameworksTuning.pdf
Arnaud Bouchez
 
EKON27-FrameworksExpressiveness.pdf
Arnaud Bouchez
 
Ekon25 mORMot 2 Server-Side Notifications
Arnaud Bouchez
 
Ekon25 mORMot 2 Cryptography
Arnaud Bouchez
 
Ekon24 from Delphi to AVX2
Arnaud Bouchez
 
Ekon24 mORMot 2
Arnaud Bouchez
 
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Arnaud Bouchez
 
Ekon23 (1) Kingdom-Driven-Design
Arnaud Bouchez
 

Recently uploaded (20)

PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Activate_Methodology_Summary presentatio
annapureddyn
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 

Ekon21 Microservices - Event Driven Design

  • 1. Microservices – Event Driven Systems Arnaud Bouchez - Synopse MICROSERVICES Event Driven Design
  • 2. Microservices – Event Driven Systems • Arnaud Bouchez – Delphi Expert • Various solutions (from Vatican to gaming industry) • IoT solution (RSI) • Real-time Monitoring solution (LiveMon) – Open Source • mORMot (SOA ORM MVC framework) • SynPDF SynMustache SynDB SynCrypto – Training and consultancy • Synopse one-man company
  • 3. Microservices – Event Driven Systems Event-Driven Systems • Using Events? • Event-Driven Design • Event-Driven mORMot
  • 4. Microservices – Event Driven Systems Using Events? • Imperative Architecture – Events are high-level commands
  • 5. Microservices – Event Driven Systems Using Events? • Imperative Architecture – Events are high-level commands • Easy modelization into regular code procedure TZen.HandleIAmGoingOut(Sender: TPeople); var temp: TTemperature; begin temp := TemperatureSensor.GetTemperature; if temp > Threshold then RoboValet.FetchDownJacket(Sender); end;
  • 6. Microservices – Event Driven Systems Using Events? • Imperative Architecture – State is stored in a main shared DB – Events are high-level commands translated into SQL statements
  • 7. Microservices – Event Driven Systems Using Events? • Imperative Architecture – State is stored in a main shared DB – Events are high-level commands translated into SQL statements • DB-centric approach • Atomicity is ensured, but history is lost • DB becomes a bottleneck
  • 8. Microservices – Event Driven Systems Using Events? • Event-Driven Architecture – Collaboration is done using Events
  • 9. Microservices – Event Driven Systems Using Events? • Event-Driven Architecture – Collaboration is done using Events Just like VCL/FMX /LCL !
  • 10. Microservices – Event Driven Systems Using Events? • Event-Driven Architecture – Collaboration is done using Events – System consists in uncoupled nodes which could be added or removed on-the-fly – Nodes publish events, and subscribe to them – Each node stores the information it needs – Some API gateways expose state via REST
  • 11. Microservices – Event Driven Systems Event-Driven Architecture • Nodes implemented as services procedure TZen.Init; begin TemperatureSensor.SubscribeToTempChange(OnTempChanged); end; procedure TZen.OnTempChanged(NewTemp: TTemperature); begin CurrentTemp := NewTemp; end; procedure TZen.HandleIAmGoingOut(Sender: TPeople); begin if CurrentTemp > Threshold then RoboValet.NotifyNeedsJacket(Sender); end;
  • 12. Microservices – Event Driven Systems Event-Driven Architecture – Collaboration is done using Events Not natural to imperative code (Delphi, C#, Java) – System consists in uncoupled nodes Architecture becomes complex – Nodes publish events, and subscribe to them May be subject to unexpected loops – Each node stores the information it needs Duplicated data, with eventual consistency
  • 13. Microservices – Event Driven Systems Event-Driven Architecture • More complex than imperative code procedure TZen.HandleIAmGoingOut(Sender: TPeople); var temp: TTemperature; begin temp := TemperatureSensor.GetTemperature; if temp > Threshold then RoboValet.FetchDownJacket(Sender); end;
  • 14. Microservices – Event Driven Systems Event-Driven Architecture • Events may be received for no use e.g. the following method is always called procedure TZen.OnTempChanged(NewTemp: TTemperature); begin CurrentTemp := NewTemp; end; but this value may never be used in procedure TZen.HandleIAmGoingOut(Sender: TPeople); begin if CurrentTemp > Threshold then RoboValet.NotifyNeedsJacket(Sender); end;
  • 15. Microservices – Event Driven Systems Event-Driven Architecture • Danger of unexpected infinite loop procedure TZen.HandleIAmGoingOut(Sender: TPeople); begin if CurrentTemp > Threshold then RoboValet.NotifyNeedsJacket(Sender); end; What happens if RoboValet.NotifyNeedsJacket triggers (indirectly) TZen.HandleIAmGoingOut ? Since nodes may be added at any time, how to prevent it to happen?
  • 16. Microservices – Event Driven Systems Event-Driven Architecture • Danger of unexpected infinite loop procedure TZen.HandleIAmGoingOut(Sender: TPeople); begin if CurrentTemp > Threshold then RoboValet.NotifyNeedsJacket(Sender); end; What happens if RoboValet.NotifyNeedsJacket triggers (indirectly) TZen.HandleIAmGoingOut ? Enter the Event-Driven debugging hell: actual event process depends on the system it runs on
  • 17. Microservices – Event Driven Systems Event-Driven Architecture • So, when to use it? – Your are modeling evolving information • e.g. scale to a lot of devices or users – You need to track changes of state • A monolithic DB only stores the current state (via Update) - otherwise it may sink under Inserts • Event-Sourcing and CQRS (see later)
  • 18. Microservices – Event Driven Systems Event-Driven Architecture • So, when to use it? – You expect a modular design • Process not written in stone during compilation (as in imperative programming): add/enable nodes to change the system behavior at runtime • Microservices, SaaS, horizontal scaling
  • 19. Microservices – Event Driven Systems Event-Driven Architecture • So, when to use it? – You defined a stateless domain • From state comes complexity, so DDD usually modelizes a time snapshot • DDD events are a way to introduce temporality – Never 100% Event-Driven • You will eventually define REST API gateways
  • 20. Microservices – Event Driven Systems Event-Driven Architecture • Message Bus – Most common way to implement Event-Driven • Cloud, Local or in-house Queues • Like VCL TApplication.ProcessMessages – Publish/Subscribe mechanism • Nodes get only needed information • Nodes could be added/removed – Used in conjunction with regular DB and REST
  • 21. Microservices – Event Driven Systems Event-Driven Architecture • Message Bus
  • 22. Microservices – Event Driven Systems Event-Driven Architecture • Peer to peer communication – Nodes communicate directly between them • Each node manages its own queue(s) • Good integration with REST • Need a centralized catalog service, P2P ZeroMQ, or convention-over-configuration setup • As offered by mORMot over WebSockets
  • 23. Microservices – Event Driven Systems Event-Driven Architecture • Event Sourcing – Business logic is implemented through Events – Events are persisted, not state • Play the events to compute a state • Intermediate states may be cached/persisted – Events are transmitted, not state • Publish/Subscribe instead of REST • Define API gateways for the outer world
  • 24. Microservices – Event Driven Systems Event-Driven Architecture • Event Sourcing – Business logic is implemented through Events – Convenient way to define Microservices • Subscribe to events, to get the information • Publish events, as result of the process – Microservices persistence • Most Microservices will use a regular state storage • Some Microservices will use Event Sourcing
  • 25. Microservices – Event Driven Systems Event-Driven Architecture • Events and CQRS – Command Query Responsibility Segregation • Commands triggers events • Events are gathered and stored • State/Events store is uncoupled from Commands – CQRS follows a non CRUD pattern • Create Read Update Delete
  • 26. Microservices – Event Driven Systems Event-Driven Architecture • CRUD DB
  • 27. Microservices – Event Driven Systems Event-Driven Architecture • CQRS DB
  • 28. Microservices – Event Driven Systems Event-Driven mORMot
  • 29. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services type ICalculator = interface(IInvokable) ['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}'] /// add two signed 32 bit integers function Add(n1,n2: integer): integer; end; – Defines the contract of the service – Microservice: should follow SOLID principles
  • 30. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services procedure ResolveCalculator(out: ICalculator); ... function TMyClient.MyAdd(a,b: integer): integer; var Calculator: ICalculator; begin Client.Services.Resolve(ICalculator, Calculator); result := Calculator.Add(a,b); end; – Runtime injection of the actual implementation • May be in-process, local or remote
  • 31. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services var Calculator: ICalculator; begin Client.Services.Resolve(ICalculator, Calculator); result := Calculator.Add(a,b); end; – Client is a mORMot TSQLRestClientURI – Will communicate using JSON over HTTP(S)
  • 32. Microservices – Event Driven Systems Event-Driven mORMot • RESTful Local and Client-Server – In-process Stand-alone client, fast server-side access – Named pipes or Windows messages Stand-alone client, fast server-side access – HTTP/1.1 via kernel-mode http.sys API • Kernel-mode execution, IOCP driven, https – Windows specific – HTTP/1.1 via OS socket API • Windows or Linux, using a Thread Pool, https via Reverse Proxy • Upgradable to WebSockets
  • 33. Microservices – Event Driven Systems Event-Driven mORMot • RESTful Client TSQLRestServer TSQLRest TSQLRestClientURI TSQLRestClient
  • 34. Microservices – Event Driven Systems Event-Driven mORMot • RESTful Server TSQLRestServerDB TSQLRestServer TSQLRest TSQLRestServerRemoteDB TSQLRestServerFullMemory
  • 35. Microservices – Event Driven Systems Event-Driven mORMot • RESTful Local and Client-Server – Needed methods are available at TSQLRest • REST auto-routing • JSON high-performance serialization • Following Liskov Substitution Principle – Focus on the logic – Abstract from the plumbing
  • 36. Microservices – Event Driven Systems Event-Driven mORMot • REST/JSON Persistence via ORM/ODM – Agnostic Storage for Events or State • ORM over local SQlite3 store • ORM over remote SQL databases • ODM over TObjectList • ODM over MongoDB Switching from one to another in a few lines of code, or through settings
  • 37. Microservices – Event Driven Systems Event-Driven mORMot • REST/JSON Persistence via ORM/ODM – Advanced ORM features • REST Convention-Over-Configuration routing • Direct DB-to-JSON serialization (no TDataSet) • Built-in statement and JSON cache • Batch (Unit-Of-Work) writes: bulk SQL/NoSQL insert • SQL logging/timing, real-time replication, data sharding, remote proxying
  • 38. Microservices – Event Driven Systems Event-Driven mORMot • Cross-platform – Main mORMot units • Delphi: Windows x86/x64 Best IDE experience for coding and debugging • FPC: Windows, MacOS, Android, Linux, BSD x86/x64, ARM32/AARCH64 (PPC32/PPC64) • (Cross)Kylix: Linux x86
  • 39. Microservices – Event Driven Systems Event-Driven mORMot • Cross-platform – Generated client code using Mustache templates • Delphi: Windows, MacOS, Android, iOS • FPC: Windows, MacOS, Android, iOS, Linux, … • (Cross)Kylix: Linux • SmartMobileStudio: JavaScript Ajax / HTML5 – Featuring almost all framework abilities • JSON marshalling, security, instance lifetime
  • 40. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Specify the callback as an interface parameter • Native way of coding in object pascal – Real-time push notifications over WebSockets • Upgraded from a standard HTTP connection – Peer To Peer communication • No need of a centralized message bus / server
  • 41. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Real-time push notifications over WebSockets
  • 42. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Specify the callback as an interface parameter ILongWorkCallback = interface(IInvokable) ... end; ILongWorkService = interface(IInvokable) ['{09FDFCEF-86E5-4077-80D8-661801A9224A}'] procedure StartWork(const workName: string; const onFinish: ILongWorkCallback); function TotalWorkCount: Integer; end;
  • 43. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Real-time push notifications over WebSockets • Once upgraded, communicates using frames over a bi-directional socket connection using application-level protocols • Security, frames gathering, REST emulation
  • 44. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Real-time push notifications over WebSockets • Once upgraded, communicates using frames over a bi-directional socket connection using application-level protocols
  • 45. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Security, Frames gathering, REST emulation • TWebSocketProtocolBinary = SynLZ + AES-256 • Regular blocking methods expecting results will be emulated like regular REST requests, with REST security and parameters marshalling • Non-blocking methods with no result will be asynchronously sent, optionally gathered as “jumbo frames”
  • 46. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Publish/Subscribe Pattern also known as “Observer” Publisher Subscriber 1 Event Subscriber 2 Event Subscriber 3
  • 47. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Beware of “Race Conditions” • Use critical sections (e.g. TSynLocker) to protect your shared data on multi-threaded server • You can gather all non-blocking callback process in a background thread via TSQLRest.AsynchRedirect
  • 48. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Beware of “Dead Locks” • If your callback triggers another method which shares the same critical section in another thread, you may block both threads • You can gather all non-blocking callback process in a background thread via TSQLRest.AsynchRedirect
  • 49. Microservices – Event Driven Systems Event-Driven mORMot • Interface-based services callbacks – Sample 31 • Long-Work Push Notification also known as “Sagas” • Publish/Subscribe Pattern also known as “Observer”
  • 50. Microservices – Event Driven Systems • Credits Martin Fowler https://martinfowler.com code and samples at https://synopse.info
  • 51. Microservices – Event Driven Systems Event-Driven Systems • Questions?