implementing an event-driven microservices architecture: a ... · implementing an event-driven...

12
Implementing an Event-Driven Microservices Architecture: A case study of Jet.com NIKHIL BARTHWAL SENIOR ENGINEER, JET.COM

Upload: others

Post on 20-Jun-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Implementing an Event-Driven Microservices Architecture: A case study of Jet.com

NIKHIL BARTHWALSENIOR ENGINEER, JET.COM

Page 2: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Background

! Launched in July 2015 !26 Million visitors a month, 25K orders daily !8 Million customers !Have 15 million SKU’s in inventory

Acquired by Walmart for $3.3 Billion in Sept 2016!

Page 3: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Architecture

!Microservices based (Over 700+ in production) !Event-Driven Architecture !Event Sourcing

Page 4: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Technology Stack

!Runs on Microsoft Azure !Uses .Net framework !Use a mix of Kafka, Redis, Splunk, Event Store, ...

Bulk of backend implemented in F#!

Page 5: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

A view of Microservice

Service (f)

Input event (x)

Output response (y)

Mathematical representation: y=f(x)

Service (f)

Input event (x)

Output response (y)

Mathematical representation: y, sout=f(x, sinp)

DB

Pure Service (Majority) No side effects except Logging

Impure service (Minority) Side effects like I/O to DB etc.

Page 6: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Why did we not use OOP?

Arguments Counter-Arguments

OOP models application as objects with state Microservices mostly don’t have states

OOP extends imperative with encapsulation and polymorphism

Imperative was designed for Van-Neumann style hardware

Microservices hosted on the cloud don’t interact with hardware directly

Being dominant paradigm, OOP Languages like Java/C# have very good ecosystem

Languages like F#/Scala can inter-operate with C#/Java seamlessly

Page 7: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Modelling a Service using FP

FP Construct Mapping to the Service world

Algebraic Data Type

Functions

Immutability

Events Modelling

Services

Events are immutable

Page 8: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Implementation: Example in F#

Define Input type Define Output type

Write a function to convert input to output…

Page 9: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Testing Microservices

WebServer

ServiceA

ServiceC ServiceD

ServiceB

ServiceE

DB

DB

Pure Services: • Being pure, behavior is very predictable • Can be tested exhaustively!

Impure Services: • Unpredictable, due to external state • Certain services can’t be tested exhaustively (e.g. Payment gateway)!

Page 10: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Benefits of using F#

!Scalability !Productivity !Code Correctness

Page 11: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Conclusion

!Very few startups scaled to Jet’s size in same time !Using F# was the most forward looking decision !Scalability, parallelism & productivity

Page 12: Implementing an Event-Driven Microservices Architecture: A ... · Implementing an Event-Driven Microservices Architecture: ... Event-Driven Architecture !Event Sourcing. Technology

Questions?

NIKHIL BARTHWALSENIOR ENGINEER, JET.COM