I had this discussion in my workplace and wanted to share and get opinions from the folks here. (I suspect StackOverflow might not appreciate such open ended questions).

Context: We have a microservice involved in pricing signalling to our users. We have an endpoint which have the following:

  • Input: an array of item ID’s
  • Output: the expected final price of the given items.

The item prices are quite volatile (and no, it is not crypto related), and is dependent on things like instantaneous supply-demand, promotions, etc.

Since the prices change quite frequently, it became a requirement that we commit to the price that was shown to the user initially, up to a certain time period (eg 5 min after the price was calculated). This improves the UX since the user will be charged as according to what they expected at the start.

Currently, in our system, we achieve this via a JWT, which contains all the details in the request, the obligatory signature, and the expiry set to 5 min from the time it was generated.

After generating this receipt, the FE can then call the endpoint with the JWT which does the actual payment processing using the params encoded in the token. This way, we know that the params + the total cost that is quoted in the JWT originates from our service since we verify that we signed it.

And the system evolves once more. We see that in the system, there is this mechanism, that if the token is expired, we do not reject the request at the charging step. Instead, we call the price endpoint internally using the params provided, and check if the price is the same as in the expired JWT. If it is the same, we process it as normal despite the JWT being expired.

This is where the contention lies. I believe that we should force the user to procure another non-expired JWT and removing this complex logic while others believe in the value of this improved UX where the user doesn’t need to restart the whole flow again.

What do y’all think? Which way would y’all architect the endpoint? Or is there something fundamentally wrong with our design (maybe JWT is not the best suited for this use case)?

  • mo_ztt ✅@lemmy.world
    link
    fedilink
    English
    arrow-up
    10
    ·
    9 months ago

    If I were a user, and the system told me that it was aware of what I wanted to do, and capable to do it, and it was in both of our financial best interests that the system fulfill my request, but it was deciding not to until I went back and jumped through an additional pointless hoop, before doing what I’d attempted to do in the first place… I definitely would be more irritated than not.

    It might be worth having a prominent notification that the system was fulfilling the expired request, so it’s not confusing that the expired tickets work sometimes and not other times. Or, maybe just tell them the JWT they’ve got is expired, and ask them yes or no if they want the new (current) price instead, and update it transparently if they say yes. You can have a higher price if it’s higher, and depending on your relationship with the customers, you could either lower the price if it’s lower or just leave it at the current price and have them get what they get. But I would definitely make things easy and smooth for the customer in this type of situation as opposed to making the system easy to make, at the expense of having them have to click through a little circular runaround when the system is aware of exactly what they’re trying to do.

  • PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    9 months ago

    From an API perspective I agree with you. From a UX perspective I agree with them.

    In the end, you’re writing software to benefit users, so user benefit is top priority.

    Luckily, you can have it both ways. Keep the API pure and simple, returning a meaningful error to the client, and the client then procures a new JWT completely transparently to the user, and retries.

    I suspect you’re overcomplicating things by using a JWT, but that kind of decision screams “confounding factors” that affect design decisions that you haven’t/can’t elaborate on. It’d just take some minor tweaks of the standard “shopping cart” API/DB design to get what you want, so I assume there is a reason you haven’t gone that route.

    • 0WN3D@lemmy.cafeOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      9 months ago

      What are the alternatives to a JWT. I know it is a bit bloated and we could just use the HS256 signature itself, but that doesn’t really change the core problem of expiry vs auto-refetch

  • xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    9 months ago

    Just my opinion here but using a signed JWT instead of a server local variable seems needlessly risky for communicating a price. Considering the potential liability to the company if your signing token is compromised I’d much rather send the prices to the user and keep a server local copy tied to the account/session/auth token. When the user tries to confirm the price we’d just pull the information from local storage.

    In terms of your primary question though… I can see the UX advantage of honoring the expired token if prices were stable but I’d probably roll out an MVP without that feature fully developed but with some logging to flag how often it’d activate - throw the statistics at business people and let them ponder how often it’d activate.

    That all said, this is an API not a GUI so I really don’t care as much about the UX since the consumer can just automate resubmitting for a new token - especially if we’re putting together an SDK or code samples for clients to run the requests and double especially if we’re controlling both ends with a distributed binary (but that doesn’t sound like the case here).

  • allywilson@sopuli.xyz
    link
    fedilink
    arrow-up
    1
    ·
    9 months ago

    I don’t really have an answer for you here, but isn’t having the expiry pointless now if you’re going to honour an elapsed token?

    The argument has become “if price X mins ago is equal to price now, honour it” - so it could have expired 10 mins ago, or 10 days ago, etc. and you’d still be honouring it, right?

    So, why have an expiry at all in this scenario? The question should become, if we’re going to honour it after 5 mins, will we honour it at 10 mins? 100 days? Which? A cut off needs to be defined.

  • The frontend should inform the user (that the “price lock” time has expired) and refresh the price automatically. Then when they click submit there should always be a non-expired token. You should also be storing details of these tokens server-side so you can validate that it’s not been tampered with (if someone gets the private key. They can submit orders for any price?)