When a major data structure has been changed in an app, what is the best way to handle such kind of errors in the front-end side so that the app doesn’t break?

For example, we have a list of users that used to have this structure:

user: {
    firstname: “John”,
    lastname: “Doe”,
         // … some other properties

And then then data structure changed to:

someuser: {
    username: “abcA”,
         // … some other properties 

Now if I go to a user’s detail that’s using the old schema in the DB, the application will break since there’s no more such thing as user.

Of course, we can have a ‘default’ error page for all unexpected / unhandled errors. But this is something that we actually expect (cos of old data structure).

Should this be handled better in the front-end side as in, we have a condition to detect if this object is using the old schema? If so, show a more specific error message OR provide a way for that object to convert into the new schema?

What’s the best practice for this?

1 Answer 1


If you expect the old data structure to exist in production, and care at all about keeping users then yes, of course you need to provide a way to convert the data. You can't just say "sorry, we changed our software, all your data is invalid".

And this conversion should absolutely not happen in the frontend - data formats is a backend issue.

There are basically two ways to do it, each with advantages and disadvantages:

  1. When you deploy the version that introduces the change, you migrate all the old data to the new format with a script.

    • Advantages: clean solution, no need to introduce complications in the code that works with the data.
    • Disadvantages: pretty much requires downtime while the conversion runs.
  2. In the backend code that loads the data from the DB, have a condition that recognizes the old format and converts it (optionally also write back the new format)

    • Advantages: no downtime needed
    • Disadvantages: uglier code, and if you have multiple changes in data structures over time it can get very ugly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.