Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
ZUHÖREN. ANALYSIEREN. BERATEN
SIDION
2
M a t t h i a s K o c h | M a r k u s G r a b e r t
J a v a F o r u m S t u t t g a r t 2 0 1 9
HALLO MICROSERVICES, GIBT’S EUCH
AUCH TRANSAKTIONAL ?
3
Service
Oriented
Architecture
Von Gartner Inc. 1996 geprägt
B e g r i f f
Hohe Investitionskosten
U n t e r n e h m e n s w e i t e r A n s a t z
„SOA ist ein Paradigma für die Strukturierung und
Nutzung verteilter Funktionalität, die von unterschiedlichen
Besitzern verantwortet wird.“
D e f i n i t i o n n a c h O A S I S ( 2 0 0 6 )
4
K a n o n i s c h e s
D a t e n m o d e l l
H o h e r A b s t i m m u n g s -
a u f w a n d
Generische Lösungen,
um allen Eventualitäten
gerecht zu werden
Wi e d e r v e r w e n d u n g
MÖGLICHE PROBLEME
MIT SOA
5
Micro-
services
Wurde 2011 zum ersten Mal verwendet
B e g r i f f
Erster Release von Dropwizard bereits Ende 2011
R e l e a s e
Unabhängige Deploymenteinheiten
Ansatz pro Service und nicht für ein gesamtes Unternehmen
A n s a t z
6
MICROSERVICES-FRAMEWORKS
7
MICROSERVICES-FRAMEWORKS
8
SERVICE-DISCOVERY
9
SERVICE-DISCOVERY
10
CONSUMER DRIVEN CONTRACTS
11
CONSUMER DRIVEN CONTRACTS
FRAMEWORKS
12
CONSUMER DRIVEN CONTRACTS
FRAMEWORKS
13
API-GATEWAY
14
Application
Gateway
Authentifizierung / Autorisierung
Routing
Protokoll-Neutralisation
Service-Discovery
Skalierung
Resillience
Asset-Verwaltung
Traffic-Shaping
Metriken
…
15
APPLICATION GATEWAYS
16
APPLICATION GATEWAYS
17
TRANSAKTIONEN FRAMEWORKS
18
Trans-
aktionen
Folge von Aktionen, die als logische Einheit
betrachtet werden
Müssen konsistenten Zustand sicherstellen
Sollten dann eingesetzt werden, wenn teilweise
Umsetzung hohe Risiken birgt
Gegenbeispiel:
Postschalter, Rathaus
Beispiel für Transaktion:
Banküberweisung
Flugbuchung
19
CAP-THEOREM
20
XA Trans-
aktionen
Locking von Daten für ggf. lange Zeit
Enge Kopplung
2-Phase-Commits (2PC)
Unterschiedliche Verfügbarkeit der Services
Heterogenes Laufzeitverhalten der Systeme
(DB/HW) Vendor specific
21
PROBLEME MIT
XA TRANSAKTIONEN
H o h e r O v e r h e a d M a s s i v e E i n s c h r ä n k u n g
p a r a l l e l e r
Ve r a r b e i t u n g
D a t e n s ä t z e b l e i b e n
( g g f . f ü r i m m e r )
g e l o c k t
R e s s o u r c e n k ö n n e n
n i c h t m e h r
v e r f ü g b a r s e i n
M o n o l i t h i s c h e s
S y s t e m
S c h w e r t e s t b a r u n d
g g f . F e h l e r a n a l y s e
t e u e r
22
Ziele
Keine Locks auf Daten
Lose Kopplung
Einfache Änderbarkeit des Systems
Einfacher Umgang mit nicht verfügbaren Services /
verlorenen Nachrichten
Generischer Ansatz um Datenkonsistenz
sicherzustellen
23
CAP-THEOREM
24
CAP-THEOREM
25
“FALSE FRIENDS”
26
Das SAGA
Pattern
„Sagas“ erstmalig 1987 als Alternative zu Long Lived
Transactions (LLT) in der Datenbank-Programmierung
vorgeschlagen
U r s p r u n g
Transaktionen in Teil-Transaktionen trennen, die sequentiell
oder auch parallel verarbeitet werden können.
Vorteil: keine längere Blockade von DB-Tabellen
Nachteil: Komplexität der Datenwiederherstellung im
Fehlerfall
I d e e
LLT blockieren Datenbank-Tabellen, behindern andere
(parallele) Prozesse
P r o b l e m
27
Das SAGA
Pattern
2012: Das Buch „SOA Pattern“ von Arnon Rotem-Gal-
Oz beschreibt ein „Saga Pattern“ für verteilte
Transaktionen jeglicher Art
Ab 2013 und 2014 mehr und mehr Diskussionen über
das Saga-Pattern im SOA und Microservices Umfeld.
2015 „Verteiltes Sagas“: mathematischer Beweis einer
orchestrierten Saga
F o r m u n g
28
IDEEN
Kompensatorische Transaktionen
Identifikation aller möglichen Zustände
Werden zu jedem Command registriert
Im Fehlerfalle werden alle
kompensatorischen Transaktionen in
inverser Reihenfolge ausgeführt
Keine Fehler durch nicht beachtete Fälle
29
KOMPENSATION
30
KOMPENSATION
31
KOMPENSATION
32
KOMPENSATION
33
KOMPENSATION
34
KOMPENSATION
35
Das SAGA
Pattern
Eventuate
https://github.com/eventuate-tram/eventuate-tram-sagas
Axon Framework
https://axoniq.io/
Diverse Drafts ohne erkennbare Fortschreibung
Eclipse Microprofile
https://github.com/eclipse/microprofile-lra
Befindet sich noch in der Entwicklung
Implementierung mittels Long-Running Actions (LRA)
I m p l e m e n t i e r u n g e n / F r a m e w o r k s
36
ECLIPSE MICROPROFILE
Starke Unterstützer (RedHat, Oracle, Microsoft,…)
Große Auswahl an Implementierungen
Ideal für Umbau von Java EE Monolithen in
Microservices
37
Microprofile
& LRA
In Entwicklung seit Juli 2017
Starke Unterstützer (RedHat, IBM)
Apache 2.0 Lizenz
Regelmäßige Fortschreibung
38
Abgrenzung
die Trigger und Zustände
garantieren, dass Trigger nicht mehrfach ausgeführt
werden
L R A s d e f i n i e r e n
Prüfung, ob kompensatorische Transaktionen
notwendig sind
das Sicherstellen der Invertierbarkeit aller Commands
die Implementierung der kompensatorischen
Transaktionen
die Persistierung der Daten für Kompensation
die Definition des Verhaltens in allen Zuständen
D i e A p p l i k a t i o n i s t z u s t ä n d i g f ü r
39
BEISPIEL FLUGBUCHUNG
Booking-
Service
+bookFlight
Flightplan-
Service
+updateFlightplan
Payment-
Service
+payment
40
ZUSTÄNDE EINER LRA
ActiveLRA
Completing Cancelling
Completed FailedToComplete Canceled FailedToCancel
Complete Cancel
StartLRA
41
ZUSTÄNDE EINER LRA
ActiveLRA
Completing Cancelling
Completed Canceled FailedToCancel
Complete Cancel
StartLRA
42
ZUSTÄNDE EINER LRA
ActiveLRA
Completing Cancelling
Completed Canceled
Complete Cancel
StartLRA
43
ZUSTÄNDE EINES PARTICIPANTS
Active
Completing Compensating
Completed FailedToComplete Compensated FailedToCompensate
Complete Compensate
join
44
ZUSTÄNDE EINES PARTICIPANTS
Active
Completing Compensating
Completed Compensated FailedToCompensate
Complete Compensate
join
45
ZUSTÄNDE EINES PARTICIPANTS
Active
Completing Compensating
Completed Compensated
Complete Compensate
join
46
Wichtige LRA
Annotations
@LRA
@Complete
@Compensate
@Status
47
Identifikation
einer LRA
LRA_HTTP_CONTEXT_HEADER
Nur annotierte JAX-RS Ressourcen nehmen an der
LRA teil
Kontext ist aber potentiell in allen Downstream-
Services verfügbar
Steuerung über HTTP Status Codes 200 bzw. 5XX
Achtung: Framework sagt nicht aus, wann eine
Methode gerufen wird. Garantiert nur deren
Ausführung
48
BEISPIEL FLUGBUCHUNG
IM ERFOLGSFALL
Booking-
Service
+bookFlight
Flightplan-
Service
Payment-
Service
add pay
ok ok
49
BOOKING-SERVICE
START EINER LRA
@Path("/")
@ApplicationScoped
public class BookService {
@LRA(LRA.Type.REQUIRES_NEW, timeLimit= 30, timeUnit=ChronoUnit.Seconds)
@Path("/book")
@PUT
public Response bookFlight(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) String
lraId, BookInfo bookInfo) {
if(book(bookInfo.getFlightInfo())) {
addFlightlist(bookInfo);
}
return Response.accepted().build();
}
…
50
FLIGHTPLAN-SERVICE
@Path("/")
@ApplicationScoped
public class FlightplanService {
@LRA(LRA.Type.REQUIRED, timeLimit= 30, timeUnit=ChronoUnit.Seconds)
@Path(“/add")
@PUT
public Repsonse addFlightlist(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) String
lraId, BookInfo bookInfo) {
if(addPassenger(bookInfo.getPassengerInfo()) {
payFlight(bookInfo.getPaymentInfo());
return Response.accepted().build();
}
else {
return Response.serverError().build();
}
…
51
PAYMENT-SERVICE
@Path("/")
@ApplicationScoped
public class PaymentService {
@LRA(LRA.Type.REQUIRED)
@Path(“/pay")
@PUT
public Response payFlight(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) String lraId,
PaymentInfo paymentInfo) {
if(pay(paymentInfo)) {
return Response.ok().build();
}
else {
return Response.serverError().build;
}
}
52
FLIGHTPLAN-SERVICE
COMPLETE
@Complete
@Path(“/complete”)
@PUT
public Response completeFlightlist(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) String lraId){
return Response.accepted().build();
}
53
BOOKING-SERVICE
COMPLETE
@Complete
@Path(“/complete”)
@PUT
public Response completeBooking(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) String lraId){
return Response.accepted().build();
}
54
BEISPIEL FLUGBUCHUNG
IM FEHLERFALL
Booking-
Service
+bookFlight
Flightplan-
Service
Payment-
Service
compensate
add pay
unbook remove
55
PAYMENT-SERVICE
COMPENSATE
@Compensate
@Path(“/compensate”)
@PUT
public Response compensatePayment(@HeaderParam(LRA_HTTP_CONTEXT_HEADER)
String lraId) {
PaymentInfo paymentInfoCompensate = getPaymentInfo(lraId);
if(!undoPay(passengerInfoCompensate)) {
backOut(lraId, passengerInfoCompensate)
}
return Response.accepted().build();
}
56
FLIGHTPLAN-SERVICE
COMPENSATE
@Compensate
@Path(“/compensate”)
@PUT
public Response removeFlightlist(@HeaderParam(LRA_HTTP_CONTEXT_HEADER)
String lraId) {
PassengerInfo passengerInfoCompensate = getPasssengerInfo(lraId);
if(!removePassenger(passengerInfoCompensate)) {
backOut(lraId, passengerInfoCompensate)
}
return Response.accepted().build();
}
57
BOOKING-SERVICE
COMPENSATE
@Compensate
@Path(“/compensate”)
@PUT
public Response compensateBooking(@HeaderParam(LRA_HTTP_CONTEXT_HEADER)
String lraId) {
BookInfo bookInfoCompensate = getBookInfo(lraId);
if(!unbookFlight(bookInfoCompensate)) {
backOut(lraId, bookInfoCompensate);
}
return Response.serverError().build();
}
58
BEISPIEL FLUGBUCHUNG
IM FEHLERFALL
Booking-
Service
+bookFlight
Flightplan-
Service
compensate
Payment-
Service
add
unbook
59
BEISPIEL FLUGBUCHUNG
TIMEOUT
Booking-
Service
+book
compensate
Flightplan-
Service
compensate
Payment-
Service
compensate
add paytimeout
60
BEISPIEL FLUGBUCHUNG
TIMEOUT
Booking-
Service
+book
compensate
Flightplan-
Service
compensate
Payment-
Service
add
timeout
6161
Look! No locks!!
62
w e n i g
L ö s u n g s a n s ä t z e
K l a s s i s c h e L ö s u n g e n
n i c h t g e e i g n e t
Nicht geeignet für
Transaktionen mit
starker Konsistenz
F r a m e w o r k L R A
FAZIT
MICROSERVICES-TRANSAKTIONEN
Open XA nicht sinnvoll
anwendbar
63
FRAGEN
Mitdenken
Mi tgesta l ten
Mi tarbe i ten
be i s id ion
POWERPOINT TEMPLATE
64
ftp://ftp.cs.princeton.edu/reports/1987/070.pdf
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.67.6951&rep=rep1&type=pdf
http://snapframework.com/
http://sparkjava.com/
http://www.royans.net/wp/2010/02/14/brewers-cap-theorem-on-distributed-systems/
https://arnon.me/2013/01/saga-pattern-architecture-design/
https://axoniq.io/
https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/
https://cararuseugeniu.blogspot.com/p/saga-pattern.html
https://codahale.com/you-cant-sacrifice-partition-tolerance
https://de.wikipedia.org/wiki/Transaktion_(Informatik)
https://docs.apigee.com/
QUELLENANGABEN
65
https://docs.microsoft.com/en-us/previous-versions/msp-n-p/jj591569(v=pandp.10)
https://dzone.com/articles/distributed-sagas-for-microservices
https://dzone.com/articles/distributed-sagas-for-microservices
https://en.wikipedia.org/wiki/CAP_theorem
https://en.wikipedia.org/wiki/Long-running_transaction
https://eventuate.io/
https://github.com/aphyr/dist-sagas/blob/master/sagas.pdf
https://github.com/eventuate-tram/eventuate-tram-sagas
https://github.com/Netflix/eureka
https://github.com/Netflix/zuul
https://graphql.org/
https://gravitee.io/
QUELLENANGABEN
66
https://helidon.io/#/
https://javalin.io/
https://konghq.com/kong/
https://ktor.io/
https://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html
https://micronaut.io/
https://microprofile.io
https://microservices.io/patterns/data/saga.html
https://netflix.github.io/falcor/
https://openliberty.io/
https://people.eecs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf
https://reflectoring.io/consumer-driven-contracts-with-angular-and-pact/
QUELLENANGABEN
67
https://spring.io/projects/spring-boot
https://spring.io/projects/spring-cloud-gateway
https://thorntail.io/
https://tyk.io/
https://vertx.io/
https://wso2.com
https://www.consul.io/discovery.html
https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
https://www.dropwizard.io
https://www.lagomframework.com/
https://www.nginx.com/
https://www.payara.fish/software/payara-server/payara-micro/
https://zookeeper.apache.org/
QUELLENANGABEN