code: public static Function<RequestEnvelope, String> userId() {
          return r -> Optional.ofNullable(r).map(RequestEnvelope::getContext)
                  .map(Context::getSystem)
                  .map(SystemState::getUser)
                  .map(User::getUserId)
                  .orElseThrow(() -> new PersistenceException("Could not retrieve user ID from request envelope to generate persistence ID"));
      }
docs: Produces a partition key from the user ID contained in an incoming request.
  @return partition key derived from user ID
  @throws PersistenceException if user ID cannot be retrieved