Using a domain model to persist metrics

I am currently developing a spring boot web application in which no entity is persistent, and hence will not be saved on a database.

Although, I need to be able to query some business metrics from it. Suppose the following scenario:

  1. EntityA belongs to a third party API.
  2. An user on my web app requests to see some details of EntityA.
  3. My app then requests EntityA from the third party API, does some processing (could be combining that data with some other available on the web), and returns the desired info to the requesting user.

I am not required to persist EntityA because it is already being persisted inside the third party API. All the processing done is transient. But, I want to be able to check how many times EntityA was requested by an user on my web application, and what data it contained on each request. This metric is useful for audit purposes, for example, since the third party accepts input and output of data. I want to be able to check who input a certain piece of data, and how many times it was done.

If I were to persist EntityA, I would not need all fields that the domain model contain. Also, I would have to add some metadata fields to it (date of request, requesting user, etc.).

What is the correct approach to it?

  1. Persist the domain model of EntityA in my web app, adding the metadata fields on, for example, a superclass?
  2. Create a new entity that express the desired metric, for example RequestedEntity, and map the desired fields of EntityA to RequestedEntity before persisting?

Go to Source
Author: Gabriel Robaina