Slide 1

Slide 1 text

E-commerce: under the hood Sean Sullivan February 21, 2017 Portland Java User Group

Slide 2

Slide 2 text

• software engineer • 20 years Java • 6 years at Gilt • back office systems @ Gilt About me

Slide 3

Slide 3 text

www.gilt.com

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Case studies • order processing • logistics invoicing • payment processing • checkout

Slide 6

Slide 6 text

Case studies • order processing • logistics invoicing • payment processing • checkout

Slide 7

Slide 7 text

2008 order processing

Slide 8

Slide 8 text

2017 discount service payment service ship calculator service order processing

Slide 9

Slide 9 text

Gilt order

Slide 10

Slide 10 text

Order items

Slide 11

Slide 11 text

ORDERS ORDER_ITEMS Domain tables

Slide 12

Slide 12 text

ORDERS orders_audit_trigger AFTER INSERT OR DELETE OR UPDATE ON orders FOR EACH ROW EXECUTE PROCEDURE orders_audit_function() ORDER_ITEMS order_items_audit_trigger AFTER INSERT OR DELETE OR UPDATE ON order_items FOR EACH ROW EXECUTE PROCEDURE order_items_audit_function() Triggers

Slide 13

Slide 13 text

ORDERS_AUDIT_LOG ORDER_ITEMS_AUDIT_LOG Audit tables

Slide 14

Slide 14 text

select id,status,submitted_at,shipped_at from orders where id = 85352432; -[ RECORD 1 ]+--------------------------- id | 85352432 status | x submitted_at | 2017-02-13 20:57:25+00 shipped_at | 2017-02-15 05:30:16.376+00

Slide 15

Slide 15 text

select count(*) from orders_audit_log where order_id = 85352432; -[ RECORD 1 ] count | 12

Slide 16

Slide 16 text

select order_id,change_type,changed_at, old_shipped_at,new_shipped_at from orders_audit_log where order_id = 85352432 and old_shipped_at is null and new_shipped_at is not null; -[ RECORD 1 ]--+------------------------------ order_id | 85352432 change_type | u changed_at | 2017-02-15 14:12:26.668751+00 old_shipped_at | new_shipped_at | 2017-02-15 05:30:16.376+00

Slide 17

Slide 17 text

More information https://wiki.postgresql.org/wiki/Audit_trigger https://wiki.postgresql.org/wiki/Audit_trigger_91plus https://github.com/2ndQuadrant/audit-trigger https://github.com/pgaudit/pgaudit

Slide 18

Slide 18 text

Case studies • order processing • logistics invoicing • payment processing • checkout

Slide 19

Slide 19 text

http://www.recode.net/2014/2/4/11623056/gilts-new-business-running-logistics-for-other-e-commerce-sites February 2014

Slide 20

Slide 20 text

February 2014

Slide 21

Slide 21 text

warehouse cloud WMS invoicing service messaging service

Slide 22

Slide 22 text

invoicing service • Scala • Akka • Squeryl • Postgres • db-journaling

Slide 23

Slide 23 text

db-journaling https://github.com/gilt/db-journaling

Slide 24

Slide 24 text

Case studies • order processing • logistics invoicing • payment processing • checkout

Slide 25

Slide 25 text

Checkout service Order processing Payment service

Slide 26

Slide 26 text

OPM (for MongoDB) https://github.com/gilt/opm

Slide 27

Slide 27 text

“OPM is a Scala library for managing the value of an object over time as a timeline of changes” https://github.com/gilt/opm

Slide 28

Slide 28 text

Demo! payment history endpoint

Slide 29

Slide 29 text

Case studies • order processing • logistics invoicing • payment processing • checkout

Slide 30

Slide 30 text

Web Checkout Android Checkout iPhone Checkout Checkout service

Slide 31

Slide 31 text

https://martinfowler.com/eaaDev/EventSourcing.html

Slide 32

Slide 32 text

https://martinfowler.com/eaaDev/EventSourcing.html “Capture all changes to an application state as a sequence of events”

Slide 33

Slide 33 text

https://martinfowler.com/eaaDev/EventSourcing.html “Event Sourcing ensures that all changes to application state are stored as a sequence of events”

Slide 34

Slide 34 text

https://martinfowler.com/eaaDev/EventSourcing.html “The key to Event Sourcing is that we guarantee that all changes to the domain objects are initiated by the event objects"

Slide 35

Slide 35 text

http://blogs.atlassian.com/2014/08/replayable-transactions-event-sourcing-dynamodb/

Slide 36

Slide 36 text

http://blogs.atlassian.com/2014/08/replayable-transactions-event-sourcing-dynamodb/ "event sourcing involves storing the sequence of events that produce the current view of the entity"

Slide 37

Slide 37 text

http://blogs.atlassian.com/2014/08/replayable-transactions-event-sourcing-dynamodb/ "an event represents an operation or transformation from one view of the entity to another"

Slide 38

Slide 38 text

http://blogs.atlassian.com/2014/08/replayable-transactions-event-sourcing-dynamodb/ “events are therefore tied to a starting view or snapshot, thus making any transformation idempotent”

Slide 39

Slide 39 text

https://github.com/gilt/lib-event-sourcing/

Slide 40

Slide 40 text

import com.gilt.eventsourcing.Transform
 import com.gilt.eventsourcing.Transform.{Delete, Insert, Update}
 import com.gilt.eventsourcing.dynamodb.DynamoDbMappingEventSource import com.gilt.eventsourcing.dynamodb.DynamoMappings.Mappings
 import com.gilt.eventsourcing.dynamodb.client.{AttributeDefinition, _}
 import com.gilt.eventsourcing.dynamodb.util.TableHelper
 lib-event-sourcing

Slide 41

Slide 41 text

object DemoDynamoDBEventSource extends DynamoDbMappingEventSource[JsValue] class DemoDynamoCommits(client: AmazonDynamoDBClient) extends DynamoCommits(client) class DemoMappingAPI(val store: Storage[Task]) extends EventSourceAPI[Task] lib-event-sourcing

Slide 42

Slide 42 text

val key = LogicalKey(uid) eventSourceApi.save( key, Some(ContentKey(Json.toJson(thing)))).run val result = eventSourceApi.get(key) lib-event-sourcing

Slide 43

Slide 43 text

def put(order: Order): Task[Try[Unit]] = { val checkoutGuid: CheckoutSessionGuid = order.sessionGuid eventSourceApi.save( LogicalKey(checkoutGuid.toString()), Some(ContentKey(Json.toJson(order)))). map(_ => Success(())). handle { case e: Exception => Failure(e) } } Gilt checkout service

Slide 44

Slide 44 text

The end

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Bonus slides

Slide 47

Slide 47 text

https://www.youtube.com/watch?v=EKdV1IgAaFc “Database as a Value”