Search code examples
architecture

Should data be standardized on the backend or the client (front-end, mobile app)?


I have a question: Should data be standardized on the backend or the client (front-end, mobile app)?

I take an example:

My return value is a json string:

{
    "product_name":"Dress X - L",
    ...
}

On the website we will display the value "Dress X - L".

But on mobile we will only display the value "X-L", so I want the client to do the extra task of cutting the returned product_name value with the "Dress" value stored in localstorage. The reason I don't want to process it on the backend is: to get the value "X-L", I have to handle some additional steps such as saving more fields in the table, making small edits and other processing.

However, client processors believe that all data needs to be processed on the backend, to be flexible in changing logic.

Our team could not agree on whether to process data on the backend or client side. The above is just a small example of mine. I would like to ask in general terms, should we standardize data on the backend or the client (front-end, mobile app)?

Thanks for all the comments on this issue!


Solution

  • My understanding is that you have a backend API and different clients, which could be mobiles, websites and more (in the future). If this is the case, then you should decouple your backend from clients. So dont design your API thinking of the clients. Do it as if you knew nothing about the clients. This way you can create an extensible, maintainable etc service.

    More specific, in your case, if you knew nothing about clients, then you should just return the json you mention and let clients handle their cases:

    {
        "product_name":"Dress X - L",
        ...
    }
    

    But, if we knew nothing about clients and still wanted to be proactive, then we could think that the info "product_name":"Dress X - L" doesnt accurate. The single responsibility principle says that variable product_name should give back just the name. but value Dress X - L gives two other things, the type (?) and sizes. So i would say you need to either have 2 more properties in there, the product type (or leave it as product name. still makes sense). and the size in a different one. Then one client can display product_name + product_size (if not null? if you have products without sizes or might in the future) and the other one can just display product_size