• caglararli@hotmail.com
  • 05386281520

Encrypted ids to break inter-service dependencies

Çağlar Arlı      -    47 Views

Encrypted ids to break inter-service dependencies

Let say I have “transactions” and “users” services managing transactions and users data respectively. Transaction record only has sender user id, but on display I want to show sender’s email. I also want to keep “transactions” as decoupled from “users” as possible. Therefore, the client calls “transactions” to get transactions and then “users” to fetch emails. Last bit - I want to enforce a rule that a user can see an email of another user only if they transacted with each other. Basically, given a JWT and a user id, “users” has to know if the JWT owner has an incoming transaction from user id without calling “transactions”.

I came up with an idea - “transactions” encrypt sender ids with a symmetric key specific to the user making request. If “users” can decrypt the id then it must come from “transactions” and thus operation properly authorized.

I wonder if this is a sound solution? Approach seems very promising as it allows one service to authorize reading of related data from another service without creating a dependency.

I considered alternatives and ruled them out:

  1. Use GraphQL - adds lot of complexity.
  2. Return user emails instead of ids from “transactions” - couples two services to each other which I’d like to avoid.