design – CQRS: getOrCreate – is this a command, query, or both?

Consider the following scenario:

  1. If the user isn’t registered in the database, register them. Return their ID.
  2. If the user is in the database, return their ID.

The API endpoint for this may look something like POST

The consumer of the API does not want to first GET a userId and, if null is returned, then POST.

Adhering to CQRS architecture and respecting REST design, if we have the POST invoke a Query first, it seems odd to have a POST that is statistically more likely to be making database queries and returning results. This Query-invoking-POST is more often than not acting as a GET.

But if we decide to have the POST invoke a Command first, it seems like an anti-pattern to have that Command exist where it is, more often than not, just performing a Query – that is, checking for the user registration in the DB and possibly returning the ID if found, never actually creating, updating, or deleting something.

What is practical approach to this situation?