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

Spree Commerce hub - technical summary

Brian Quinn
September 17, 2013
180

Spree Commerce hub - technical summary

Brian Quinn

September 17, 2013
Tweet

Transcript

  1. Spree Commerce hub

    View full-size slide

  2. Spree Commerce
    hub
    Overview

    View full-size slide

  3. Spree Commerce
    store front
    Spree Commerce
    hub
    Overview

    View full-size slide

  4. Spree Commerce
    store front
    Spree Commerce
    hub
    Overview

    View full-size slide

  5. Spree Commerce
    store front
    Spree Commerce
    hub
    Mandrill
    NetSuite
    Shipwire
    Custom
    Overview

    View full-size slide

  6. Spree Commerce
    store front
    Spree Commerce
    hub
    Mandrill
    NetSuite
    Shipwire
    Custom
    SendGrid
    Xero
    Amazon
    Custom
    So
    Ne
    E
    Cu
    Overview

    View full-size slide

  7. Store front hub
    Mandrill
    Endpoint
    Overview

    View full-size slide

  8. Store front hub
    orders updated since (timestamp)
    updated orders
    Mandrill
    Endpoint
    Overview

    View full-size slide

  9. Store front hub
    orders updated since (timestamp)
    updated orders
    Mandrill
    Endpoint
    detect new orders
    Overview

    View full-size slide

  10. Store front hub
    orders updated since (timestamp)
    updated orders
    Mandrill
    Endpoint
    send order confirmation email
    detect new orders
    confirmation
    Overview

    View full-size slide

  11. Store front hub
    orders updated since (timestamp)
    updated orders
    confirmation
    Overview

    View full-size slide

  12. Store front hub
    orders updated since (timestamp)
    updated orders
    send shipment to fulfillment
    detect ready shipments
    confirmation
    Shipwire
    Endpoint
    Overview

    View full-size slide

  13. Store front hub
    Shipwire
    Endpoint
    Overview

    View full-size slide

  14. Store front hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    Overview

    View full-size slide

  15. Store front hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    update shipment state + tracking
    confirmation
    Overview

    View full-size slide

  16. Store front hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    update shipment state + tracking
    confirmation
    Overview

    View full-size slide

  17. hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    + tracking
    Mandrill
    Endpoint
    Overview

    View full-size slide

  18. hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    + tracking
    Mandrill
    Endpoint
    Overview

    View full-size slide

  19. hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    + tracking
    Mandrill
    Endpoint
    send shipment notification email
    Overview

    View full-size slide

  20. hub
    poll for shipments (bookmark)
    dispatched shipments
    Shipwire
    Endpoint
    + tracking
    Mandrill
    Endpoint
    send shipment notification email
    confirmation
    Overview

    View full-size slide

  21. Message Basics

    View full-size slide

  22. Message: Overview
    1 {
    2 "message": "payment:ready",
    3 "payload": {
    4 "payment": {
    5 "id": 15913,
    6 "amount": "129.57",
    7 "state": "pending",
    8 "payment_method": {
    9 "id": 931422127,
    10 "name": "Credit Card",
    11 "environment": "production"
    12 }
    13 }
    14 }
    15 }

    View full-size slide

  23. Message: Overview
    1 {
    2 "message": "payment:ready",
    3 "payload": {
    4 "payment": {
    5 "id": 15913,
    6 "amount": "129.57",
    7 "state": "pending",
    8 "payment_method": {
    9 "id": 931422127,
    10 "name": "Credit Card",
    11 "environment": "production"
    12 }
    13 }
    14 }
    15 }

    View full-size slide

  24. Message: Overview
    1 {
    2 "message": "payment:ready",
    3 "payload": {
    4 "payment": {
    5 "id": 15913,
    6 "amount": "129.57",
    7 "state": "pending",
    8 "payment_method": {
    9 "id": 931422127,
    10 "name": "Credit Card",
    11 "environment": "production"
    12 }
    13 }
    14 }
    15 }

    View full-size slide

  25. Order New order:new
    Order Updated order:updated
    Order Cancelled order:cancelled

    View full-size slide

  26. Order New order:new
    Order Updated order:updated
    Order Cancelled order:cancelled
    Shipment Confirmation shipment:confirm
    Shipment Ready shipment:ready

    View full-size slide

  27. Order New order:new
    Order Updated order:updated
    Order Cancelled order:cancelled
    Payment Ready payment:ready
    Shipment Confirmation shipment:confirm
    Shipment Ready shipment:ready
    Payment Captured payment:captured
    Payment Declined payment:declined

    View full-size slide

  28. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "message": "payment:ready",
    4 "payload": { ... },
    5 "parameters": [
    6 {
    7 "name": "quickbooks.user_name",
    8 "value": "iQ55k..."
    9 },
    10 {
    11 "name": "quickbooks.password",
    12 "value": "YQoQS..."
    13 }
    14 ]
    15 }
    Message: Parameters

    View full-size slide

  29. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "message": "payment:ready",
    4 "payload": { ... },
    5 "parameters": [
    6 {
    7 "name": "quickbooks.user_name",
    8 "value": "iQ55k..."
    9 },
    10 {
    11 "name": "quickbooks.password",
    12 "value": "YQoQS..."
    13 }
    14 ]
    15 }
    Message: Parameters

    View full-size slide

  30. Message Flow

    View full-size slide

  31. MSG
    Message Flow

    View full-size slide

  32. MSG
    Incoming
    Queue
    Message Flow

    View full-size slide

  33. MSG
    Incoming
    Queue Router
    Message Flow

    View full-size slide

  34. MSG
    Incoming
    Queue Router
    Message Flow

    View full-size slide

  35. MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Message Flow

    View full-size slide

  36. MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Accepted
    Queue
    Message Flow

    View full-size slide

  37. order:new
    MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Accepted
    Queue
    Message Flow

    View full-size slide

  38. order:new
    1 x order:new
    MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Accepted
    Queue
    Message Flow

    View full-size slide

  39. order:new
    1 x order:new
    order:new
    - Mandrill
    - NetSuite
    - MixPanel
    MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Accepted
    Queue
    Message Flow

    View full-size slide

  40. order:new
    1 x order:new
    order:new
    - Mandrill
    - NetSuite
    - MixPanel
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    MSG
    Incoming
    Queue Router
    Consumer
    Registry
    Accepted
    Queue
    Message Flow

    View full-size slide

  41. Accepted
    Queue
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  42. Accepted
    Queue Dispatcher
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  43. Accepted
    Queue Dispatcher
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  44. Accepted
    Queue Dispatcher
    Mandrill
    order:new
    1
    MixPanel
    order:new
    3
    NetSuite
    order:new 2
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  45. Accepted
    Queue Dispatcher
    Mandrill
    order:new
    1
    MixPanel
    order:new
    3
    NetSuite
    order:new 2
    200: success
    200: success
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  46. Accepted
    Queue Dispatcher
    Mandrill
    order:new
    1
    MixPanel
    order:new
    3
    NetSuite
    order:new 2
    200: success
    200: success
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  47. Accepted
    Queue Dispatcher
    Mandrill
    order:new
    1
    MixPanel
    order:new
    3
    NetSuite
    order:new 2
    200: success
    200: success
    500: fail!
    3 x order:new
    - Mandrill
    - NetSuite
    - MixPanel
    Message Flow

    View full-size slide

  48. Accepted
    Queue Dispatcher NetSuite
    1 x order:new
    - NetSuite
    Message Flow

    View full-size slide

  49. Accepted
    Queue Dispatcher NetSuite
    order:new 2
    500: fail!
    1 x order:new
    - NetSuite
    order:new 2
    500: fail!
    order:new 2
    500: fail!
    order:new 2
    200: success
    Message Flow

    View full-size slide

  50. Accepted
    Queue Dispatcher NetSuite
    order:new 2
    500: fail!
    1 x order:new
    - NetSuite
    order:new 2
    500: fail!
    order:new 2
    500: fail!
    order:new 2
    200: success
    Message Flow

    View full-size slide

  51. Order V1
    parent: null
    new
    Versioning

    View full-size slide

  52. Order V1
    parent: null
    new
    send order
    confirmation
    email
    Versioning

    View full-size slide

  53. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    send order
    confirmation
    email
    Versioning

    View full-size slide

  54. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    send order
    confirmation
    email
    capture
    payment
    Versioning

    View full-size slide

  55. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    Order V3
    parent: V2
    update
    send order
    confirmation
    email
    capture
    payment
    Versioning

    View full-size slide

  56. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    Order V3
    parent: V2
    update
    send order
    confirmation
    email
    capture
    payment
    send
    shipment to
    fulfillment
    Versioning

    View full-size slide

  57. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    Order V3
    parent: V2
    update update
    Order V4
    parent: V3
    send order
    confirmation
    email
    capture
    payment
    send
    shipment to
    fulfillment
    Versioning

    View full-size slide

  58. Order V1
    parent: null
    Order V2
    parent: V1
    update
    new
    Order V3
    parent: V2
    update update
    Order V4
    parent: V3
    send order
    confirmation
    email
    capture
    payment
    send
    shipment to
    fulfillment
    send
    shipment
    confirmation
    Versioning

    View full-size slide

  59. Versioning
    Implying events

    View full-size slide

  60. Order V1
    state: complete
    Versioning

    View full-size slide

  61. Order V1
    state: complete
    update
    Order V2
    state: canceled
    Versioning

    View full-size slide

  62. Order V1
    state: complete
    update
    Order V2
    state: canceled
    push
    message
    order:update
    Versioning

    View full-size slide

  63. Order V1
    state: complete
    update
    Order V2
    state: canceled
    order:canceled
    push
    message
    order:update
    Versioning

    View full-size slide

  64. Messages (8)

    View full-size slide

  65. Messages (10)

    View full-size slide

  66. Custom Endpoints

    View full-size slide

  67. Message: message_id
    1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "message": "payment:ready",
    4 "payload": {
    5 "payment": {
    6 "id": 15913,
    7 "amount": "129.57",
    8 "state": "pending",
    9 "payment_method": {
    10 "id": 931422127,
    11 "name": "Credit Card",
    12 "environment": "production"
    13 }
    14 }
    15 }
    16 }

    View full-size slide

  68. Message: message_id
    1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "message": "payment:ready",
    4 "payload": {
    5 "payment": {
    6 "id": 15913,
    7 "amount": "129.57",
    8 "state": "pending",
    9 "payment_method": {
    10 "id": 931422127,
    11 "name": "Credit Card",
    12 "environment": "production"
    13 }
    14 }
    15 }
    16 }

    View full-size slide

  69. Dispatcher Endpoint
    order:new

    View full-size slide

  70. Dispatcher Endpoint
    POST JSON
    { ... }
    order:new

    View full-size slide

  71. Dispatcher Endpoint
    {message_id: x}
    HTTP: 200
    POST JSON
    { ... }
    order:new

    View full-size slide

  72. Dispatcher Endpoint
    {message_id: x}
    HTTP: 200
    POST JSON
    { ... }
    order:new
    --------------- ✓

    View full-size slide

  73. Response: Basic
    1 {
    2 "message_id": "518783ac7575e46507000001"
    3 }

    View full-size slide

  74. Endpoint: Sinatra
    1 require 'sinatra'
    2 require 'sinatra/json'
    3
    4 class SimpleEndpoint < Sinatra::Base
    5 helpers Sinatra::JSON
    6
    7 post '/' do
    8 message = JSON.parse(request.body.read)
    9
    10 json 'message_id' => message['message_id']
    11 end
    12 end

    View full-size slide

  75. Endpoint: Sinatra
    1 require 'sinatra'
    2 require 'sinatra/json'
    3
    4 class SimpleEndpoint < Sinatra::Base
    5 helpers Sinatra::JSON
    6
    7 post '/' do
    8 message = JSON.parse(request.body.read)
    9
    10 json 'message_id' => message['message_id']
    11 end
    12 end

    View full-size slide

  76. Endpoint: Sinatra
    1 require 'sinatra'
    2 require 'sinatra/json'
    3
    4 class SimpleEndpoint < Sinatra::Base
    5 helpers Sinatra::JSON
    6
    7 post '/' do
    8 message = JSON.parse(request.body.read)
    9
    10 json 'message_id' => message['message_id']
    11 end
    12 end
    <- DO INTERESTING THINGS HERE

    View full-size slide

  77. Endpoint Base
    https://github.com/spree/endpoint_base

    View full-size slide

  78. Example: Endpoint Base
    1 class SimpleEndpoint < EndpointBase
    2 post '/' do
    3 process_result 200, {'message_id' => @message['message_id'] }
    4 end
    5 end

    View full-size slide

  79. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "notifications": [
    4 { "level": "info",
    5 "subject": "Shipment accepted",
    6 "description": "Shipment H123456 was accepted by 3PL"
    7 }
    8 ],
    9 }
    Response: Notifications

    View full-size slide

  80. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "notifications": [
    4 { "level": "info",
    5 "subject": "Shipment accepted",
    6 "description": "Shipment H123456 was accepted by 3PL"
    7 }
    8 ],
    9 }
    Response: Notifications

    View full-size slide

  81. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "notifications": [{"level": "info", "subject": "it happened"}],
    4 "messages": [
    5 {
    6 "message": "payment:captured",
    7 "payload": {
    8 “amount": 129.99,
    9 }
    10 }
    11 ]
    12 }
    Response: Messages

    View full-size slide

  82. 1 {
    2 "message_id": "518783ac7575e46507000001",
    3 "notifications": [{"level": "info", "subject": "it happened"}],
    4 "messages": [
    5 {
    6 "message": "payment:captured",
    7 "payload": {
    8 “amount": 129.99,
    9 }
    10 }
    11 ]
    12 }
    Response: Messages

    View full-size slide