Constants vs Database

Certified Lead Developer

Hi all,

I am developing an application that contains a questionnaire with around 20 questions. There are also around 10 sections to display help. 

Both questions and help can be updated by the users. 

I dont know if I should create 30 constants or store the data in the DB.

For performance reasons I think is better to use constants but for memory management and scalability I think the DB makes more sense.

Is there any recommendation about this?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Thanks all for your answers. The questions will be updated rarely. I have already built a way to update constants through an "admin ui" to allow the users to do that themselves. It works quite fast. But now that I see that the number of questions is not small (30 for now) I wonder if the best practice would be to store the questions in the DB

Reply
  • 0
    Certified Lead Developer

    Thanks all for your answers. The questions will be updated rarely. I have already built a way to update constants through an "admin ui" to allow the users to do that themselves. It works quite fast. But now that I see that the number of questions is not small (30 for now) I wonder if the best practice would be to store the questions in the DB

Children
  • 0
    Certified Lead Developer
    in reply to jesusa310

    Updated how rarely?

    If you can count the times annually on one hand, you probably have the ideal solution already.

    I'd say as it starts to increase beyond that frequency, or if the number of questions starts growing far above 30, you start eyeing the DB option more and more.

  • So, here's the thing: at one extreme of the thought spectrum is: "If a requirement isn't written down it doesn't exist!"...and at the other there's the "I just KNOW you're going to ask for this 3 months down the line...and even if you don't I'm going to make this as flexible as possible because that's just the best design!". That's the role of the Consultant, to make decisions based upon educated guesses and informed by (sometimes hard!) experience.

    I try ONLY to use Constants where the value is "one-dimensional" - that is, it has a single value & there are no associated or related attributes - and is genuinely static - that is I KNOW it'll (almost) never change.

    Otherwise it goes into the DB. Yes, there's a performance overhead (because you don't get something for nothing - that's a fundamental law of the Universe, don't argue with me, take it up with Einstein!)...but I've found that mostly the overhead IS NOT MATERIAL! That is, hey it takes 10 times as long, but the difference is between 0.01s and 0.1s (your mileage may vary here!) So does that really matter?!? And isn't what you're buying for this worth it? Those are the considerations that should be brought to bear when deciding which way to go. And with Appian the speed of delivery (and ease of maintenance) can and should reduce the resistance to opting for the more "complex, flexible, maintainable" options.