I have a question about memory consumption when receiving a frontend request, for example.
In this first example, let’s suppose that the user created an order
"order": {
"order_code": "123",
"items": [
{
name: "item name 1",
quantity: 1,
price: 100.0
},
{
name: "item name 2",
quantity: 2,
price: 100.0
},
{
name: "item name 3",
quantity: 3,
price: 100.0
}
]
}
And each item should have the same “order_code” too, for some logic business.
In the backend, we should map each item and copy the order_code
inside it.
In this second example, the frontend is responsible for sending the order_code
for each item and the backend should validate if the order_code
in each item is equal to the order’s order_code
.
(The customer don’t need to see this field as long as the frontend send as a “hidden” input, for example)
"order": {
"order_code": "123",
"items": [
{
name: "item name 1",
quantity: 1,
price: 100.0,
order_code: "123"
},
{
name: "item name 2",
quantity: 2,
price: 100.0,
order_code: "123"
},
{
name: "item name 3",
quantity: 3,
price: 100.0,
order_code: "123"
}
]
}
Creating some test using Grafana and Prometheus, I had some results where the request duration in milliseconds was higher in the first example than the second.
But, using erlang.memory(:total)
the second example was consuming more memory than the first example for some reason.
I thought that in the first example the memory consumption would be greater, as another data is created in memory for the new items with order_code
.
How does memory consumption work in this case?
Is it advisable to do this type of mapping in Backend or should we just validate the data?