Imagine a application similar to Facebook, where you have status updates and a news feed. The names and profile pictures can be changed. There are also several different types of updates requiring a different layout template for each type.

I hate my implementation and would like some feedback on how to improve it. When I store the status update in the database, I basically store the HTML template in the database with some of the update specific information in it as well. Since the profile pic and poster name can change, I'm keeping placeholders in the HTML stored in the database like '{USER_PROFILE_PIC}' and replacing that with the most current value when the record is pulled & displayed. I hate doing it this way because if we want to do a design change down the road, we are stuck with this HTML in the database.

I'm doing this all in SQL Server. I'm open to other databases if needed, I just am looking for a good way to pull dynamic status updates from a database and display them with up to the moment info.


  • 1
    why are you putting html in your database? what web stack are you running this on? – spaceman Aug 14 '13 at 8:41
  • @spaceman good question. I was having a very slow response loading the template based on the update type and munging all of the different data elements into the update. So I was basically keeping the template html, and most of the update specific info, in a SQL field. It's obviously not ideal, so if you have any recommendations I'd love to hear them. Also I'm using MVC 3 ASP.NET. Thanks. – Jeff Borden Aug 15 '13 at 21:58
  • Have you profiled your app and database to see what specifically is causing the slow response? You also might consider client side templating. – GrandmasterB Aug 16 '13 at 16:19

Ok, if you're using mvc then you're definitely doing this a bit wrong... Consider mvc, its the model => view => controller framework. The whole point of the framework is to ensure a nice and clean separation of concerns.

When you start storing templates in your db, your muddling those concerns. What I would do is convert each of my templates into a partial view. The whole reason partial views exist is to serve as little code templates.

I would store the data only in the database.

So your app basically has this:

the db containing only the data required for a status update. a controller that loads this data, and then passes it to the relevant view a view that displays the data in its own required format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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