Upgrade to Pro — share decks privately, control downloads, hide ads and more …

E-commerce under the hood

99d4c0ed3c8027ea1c37b53d6441d042?s=47 sullis
February 21, 2017

E-commerce under the hood

Portland Java User Group
February 21, 2017
Portland Oregon
keywords: Java, Scala, Ruby, Postgres, MongoDB, DynamoDB, Gilt

99d4c0ed3c8027ea1c37b53d6441d042?s=128

sullis

February 21, 2017
Tweet

Transcript

  1. E-commerce: under the hood Sean Sullivan February 21, 2017 Portland

    Java User Group
  2. • software engineer • 20 years Java • 6 years

    at Gilt • back office systems @ Gilt About me
  3. www.gilt.com

  4. None
  5. Case studies • order processing • logistics invoicing • payment

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

    processing • checkout
  7. 2008 order processing

  8. 2017 discount service payment service ship calculator service order processing

  9. Gilt order

  10. Order items

  11. ORDERS ORDER_ITEMS Domain tables

  12. 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
  13. ORDERS_AUDIT_LOG ORDER_ITEMS_AUDIT_LOG Audit tables

  14. 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
  15. select count(*) from orders_audit_log where order_id = 85352432; -[ RECORD

    1 ] count | 12
  16. 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
  17. 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

  18. Case studies • order processing • logistics invoicing • payment

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

  20. February 2014

  21. warehouse cloud WMS invoicing service messaging service

  22. invoicing service • Scala • Akka • Squeryl • Postgres

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

  24. Case studies • order processing • logistics invoicing • payment

    processing • checkout
  25. Checkout service Order processing Payment service

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

  27. “OPM is a Scala library for managing the value of

    an object over time as a timeline of changes” https://github.com/gilt/opm
  28. Demo! payment history endpoint

  29. Case studies • order processing • logistics invoicing • payment

    processing • checkout
  30. Web Checkout Android Checkout iPhone Checkout Checkout service

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

  32. https://martinfowler.com/eaaDev/EventSourcing.html “Capture all changes to an application state as a

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

    are stored as a sequence of events”
  34. 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"
  35. http://blogs.atlassian.com/2014/08/replayable-transactions-event-sourcing-dynamodb/

  36. 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"
  37. 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"
  38. 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”
  39. https://github.com/gilt/lib-event-sourcing/

  40. 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
  41. object DemoDynamoDBEventSource extends DynamoDbMappingEventSource[JsValue] class DemoDynamoCommits(client: AmazonDynamoDBClient) extends DynamoCommits(client) class

    DemoMappingAPI(val store: Storage[Task]) extends EventSourceAPI[Task] lib-event-sourcing
  42. val key = LogicalKey(uid) eventSourceApi.save( key, Some(ContentKey(Json.toJson(thing)))).run val result =

    eventSourceApi.get(key) lib-event-sourcing
  43. 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
  44. The end

  45. None
  46. Bonus slides

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