Does Schema Validation Have a Performance Penalty?

Hi!
I’ve been doing some research and I’m having trouble finding information on the relationship between schema validation and performance. I’m specifically interested in whether implementing schema validation for a high-traffic collection, like one serving a busy mobile app with lots of writes, can have a negative impact on performance. Do you have any idea if this is the case? If so, could you give me an idea of how significant the impact might be? Thanks so much for your help.

Like anything there is not such thing as no cost computing.

Very personal opinion.

Schema validation add computing complexity. How much? I do not know. What I know is that when your code is well tested, you do not need schema validation since your code will create and update the data correctly. You do not need this extra layer of protection. Italicized protection or obstruction. Or obstruction, yes. In the field, despite code that is tested, you might need to patch thing and sometimes schema validation is on the way because to make things works you have to break the schema.

Yes it is good to prevent human from entering bad data. But my point is validate the data as early as possible because the closer it is to the user, it is more responsive and naturally distributed.

@steevej is right about cost, but I’d like to offer a differing perspective.

I’m a “belt-and-suspenders” designer. Surely you should validate input at the user interface. But the fallback is validation. It’s not usually so costly in execution, and it takes one more step to guarantee the integrity of the data.

I use MongoDB professionally and like it, but there are some odd notions going around. One cannot reasonably hold in one’s head both notions that:

  1. MongoDB is totally enterprise-ready and a reasonable replacement for half a century of relational database development, and
  2. MongoDB gives you total freedom and all the safeguards developed over the decades can be blithely discarded because, you know, freedom … :grin:

So I use validation. It doesn’t cost much and it gives me a warm, safe feeling.

1 Like

@steevej @Jack_Woehr
Thank you for the detailed input!

So I use validation. It doesn’t cost much and it gives me a warm, safe feeling.

I completely agree about the safe warm feeling (-:
The question is again, how much overhead are we talking about?
To give more context, our application is more “tall” than “wide”. So it’s not that high on features and business entities and sprawl of domain logic (what you might call an “enterprise app”). But it has very high live traffic coming currently from mobile devices.
Any idea where to dig in order to get a more technical answer on that?

I’ve never seen any figures on that.

I suppose one might have to set up an experiment and measure it.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.