Bending Spark towards enterprise needs

33
BENDING SPARK TOWARDS ENTERPRIZE NEEDS BORIS TROFIMOV @ SIGMA SOFTWARE

Transcript of Bending Spark towards enterprise needs

Page 1: Bending Spark towards enterprise needs

BENDINGSPARKTOWARDSENTERPRIZE NEEDS

BORISTROFIMOV@SIGMASOFTWARE

Page 2: Bending Spark towards enterprise needs
Page 3: Bending Spark towards enterprise needs
Page 4: Bending Spark towards enterprise needs
Page 5: Bending Spark towards enterprise needs

USERINTERFACE

SERVICELAYER

DATASTORE

CLASSIC APPROACH

Page 6: Bending Spark towards enterprise needs

PRESENTATIONLAYER

APPLICATIONSERVICES

DOMAINLAYER

DAL

INFRASTRUCTURE

CLASSIC LAYERS

Page 7: Bending Spark towards enterprise needs
Page 8: Bending Spark towards enterprise needs

CLASSIC APPROACH

USERINTERFACE

SERVICELAYER

DATASTORE

Page 9: Bending Spark towards enterprise needs

CQRS

USERINTERFACE

SERVICELAYER

DATASTORE

COMMAND/WRITEMODEL READMODEL

Page 10: Bending Spark towards enterprise needs

CQRS NAKEDUSERINTERFACE

SERVICELAYERWRITESTORE

COMMANDBUS

COMMANDHANDLER

REPOSITORY

DomainModel Domain

Model

EVENTBUS

EVENTHANDLER

Commands

READMODELSTORE

QUERYFACADE

Query DTO

WRITEMODEL READMODEL

Page 11: Bending Spark towards enterprise needs

USERINTERFACE

MULTIPLE READMODELSUSERINTERFACE

SERVICELAYERWRITESTORE

COMMANDBUS

COMMANDHANDLER

REPOSITORY

DomainModel Domain

Model

EVENTBUS

EVENTHANDLER

Commands

EVENTHANDLER

READMODELSTORE1

READMODELSTORE2

QUERYFACADE QUERYFACADE

WRITEMODEL READMODEL

Page 12: Bending Spark towards enterprise needs

BULLETIN BOARDAPP

Page 13: Bending Spark towards enterprise needs

APPLICATIONFEATURES

•ADDBulletinwithspecificauthornameandmessage•VIEWlistofpublishedbulletins

Page 14: Bending Spark towards enterprise needs

SERVICELAYER

SPARKISCOMINGUSERINTERFACE

MONGOREAD/WRITESTORE

KAFKA

COMMANDHANDLER

REPOSITORY

DomainModel Domain

Model

Commands

QUERYFACADE

Query DTO

WRITEMODEL READMODELSPARK

Page 15: Bending Spark towards enterprise needs

SERVICELAYER

SPARKISCOMINGUSERINTERFACE

MONGOREAD/WRITESTORE

KAFKA

COMMANDHANDLER

REPOSITORY

DomainModel Domain

Model

Commands

QUERYFACADE

Query DTO

WRITEMODEL READMODELSPARK

SHAREDSTORE

Page 16: Bending Spark towards enterprise needs

TECHNOLOGY STACK

FAÇADE• Java8• SpringBoot&MVC• Mongo

COMMANDPROCESSOR• Kafka0.9.0.1• Scala2.11• Spark2.0.0Streaming

Page 17: Bending Spark towards enterprise needs

DEPLOYMENT VIEW

DOCKER

KAFKAZOOKEEPER

MONGO

DEVMACHINE

LOCALSPARK

FACADE

Page 18: Bending Spark towards enterprise needs

DEMO

https://github.com/btrofimov/spark-enterprise-example/tree/master/nonblocking-bulletinboard

Page 19: Bending Spark towards enterprise needs
Page 20: Bending Spark towards enterprise needs

WAIT

Page 21: Bending Spark towards enterprise needs

WELCOMETOASYNCHONOUSHELL

ATLEASTFOURSOLUTIONS

• C'mon,it’sOK

• Pullingserviceuntilentityisadded

• Addpushchannelanddelivereventsupstairs

• MakeRESTmethodsblockeduntilcommandisfinished

Page 22: Bending Spark towards enterprise needs

MAKEITSYNCHRONOUS

Page 23: Bending Spark towards enterprise needs

DEMO2

https://github.com/btrofimov/spark-enterprise-example/tree/master/blocking-bulletinboard

Page 24: Bending Spark towards enterprise needs

RETROSPECTIVE

Page 25: Bending Spark towards enterprise needs

READMODELinstances

WRITEMODELinstances

EFFICIENT SCALEOUTSEPARATEDSCALEOUTDEPENDINGONMODEL

NEEDS

Page 26: Bending Spark towards enterprise needs

dataStream.foreachRDD { rdd =>

val values = rdd.values

values.map { cmdMessage =>…

}.foreach { cmdMessage =>

…}

}

DESERIALIZATION ERRORS

MIGHTFAILDURINGLAUNCHIFPIPELINEHASBEENCHANGED

RISK: AFFECTSCHECKPOINTS

Page 27: Bending Spark towards enterprise needs

DESERIALIZATION ERRORS

• Hardtokeepcodetoleranttotheseerrorsandtestableatthesametime.• SparkwithKafkaconnector0.10allowstosaveKafkaoffsetsanditispossibletorestorefromtheminsteadofcheckpoints.

Page 28: Bending Spark towards enterprise needs

THROUGHPUT VSLATENCY

Spark-basedserviceshavenicethroughputhoweverduetointernaloverheadstheyhavelowerlimitonlatency

Page 29: Bending Spark towards enterprise needs

IDENTIFIER ASSIGNRESPONSIBILITY

• Clientgeneratesuniqueidentifiersandpassesittoservice• Servicegeneratesuniqueidentifierandpassesitbacktoclient

Page 30: Bending Spark towards enterprise needs

EVENTUALVS STRONG CONSISTENCY

• CQRSappsusuallyareeventuallyconsistent• ChoosewiselybetweenCQRSandtraditionalapproach• Consideroptimisticorpessimisticlockingtoachievestrongconsistency• Insomecasesdefinedreasonabletimeoutsorin-progresslistsmighthelptosolveraceconditions(dependsoncommandroundtrips)

Page 31: Bending Spark towards enterprise needs

FAULTTOLERANCE

Page 32: Bending Spark towards enterprise needs

FAULTTOLERANCE

• Sparkautorerunstaskstomitigatenetworkorotheroutages• Easyandsafeapplicationrestartbasedoncheckpoints

Page 33: Bending Spark towards enterprise needs

THANKYOU

slides code