Skip to content

Instantly share code, notes, and snippets.

@joshuacullenlux
Last active March 4, 2019 01:04
Show Gist options
  • Save joshuacullenlux/ad6c42f36239eb89ddab8a5a85b31130 to your computer and use it in GitHub Desktop.
Save joshuacullenlux/ad6c42f36239eb89ddab8a5a85b31130 to your computer and use it in GitHub Desktop.
Many item order flow

Problem

Our current purchase flow is the following:

  1. Create order
  2. Add accommodation item 1
  3. Add accommodation item 2...
  4. Finalize order
  5. Do payments

This happens all at the same time on payment. It worked because a user would generally only add one or two items to an order at a time but as we are adding new types of items to an order this will not scale.

Potential Solutions

1. One request all items

One approach would be to bundle all the items into a singular request and add them at the same time. We will setup some kind of polling or workers from order to flights:

  1. Create order with items and finalize
  2. Do payments

Benefits

  • We only have one request so potential network dropouts are limited
  • It will be quicker as the network roundtrip is minimized

Drawbacks

  • Some items could take a long time to be added (flights). This means we will potentially hit the heroku timeout of 30s. We would need to solve this by polling or something similar
  • An order will be blocked by a single item even though the rest have been added. For example we book 2 hotel rooms, 3 addons and then the flights price has changed so that item is rejected. The user would have to start again and the order be cleaned up (already solved).

2. Add items to an order individually

We could also continue to add the items to the order individually.

  1. Create order on calendar page
  2. Add the hotel after calendar
  3. Add the addons
  4. Add flights after traveller form
  5. Finalize
  6. Do payments

Benefits

  • Item inventory is locked down for a user at the time it's added
  • Less chance of the user being rejected at payment as the items are already in the order
  • Individual requests mean we wont hit the network timeout

Drawbacks

  • Inventory is taken before a user decides to pay. We could book out hotels without selling any
  • The client must keep track of the order state. Items will need to be updateable/deleteable from an order (no small feat)
  • We will need to handle orders being abandoned. This means showing a clock or something similar (19:59 minutes remaining)
@joshuacullenlux
Copy link
Author

Feel free to edit and add solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment