All in the <head>

– Ponderings & code by Drew McLellan –

– Live from The Internets since 2003 –

About

Scalability vs Performance

5 July 2004

When designing the architecture for a web application, it is normally desirable to design every aspect of the system to be as scalable as possible. It’s only too often that badly designed apps have need to be completely refactored before any further development work can be done, entirely due to an unscalable architecture. If the app hasn’t been designed with an attitude of what if we wanted to …? then adding a dot-dot-dot six months down the line can be a massive undertaking with needless slaughtering of otherwise good code.

But we know this; we know that applications, any code in fact, needs to be designed to cope effectively with change. It’s one of the principals behind OO and it’s generally accepted as A Good Thing. This is typically done through the use of OO design principals closely coupled with various levels of abstraction. The question it raises, however, is where do we stop? At what point does multiple levels of abstraction stop saving development time and start taking its toll on performance?

Take the example of database normalisation. If adhering to third level of normalisation completely, theory would have us storing tables full of things like postal codes. It’s possible that two users could have the same postal code, and our design should not allow that data to be stored twice. Of course, the reality in a global information system like a web application is that it’s very unlikely that a reasonable quantity of users will live only a few doors apart, and even if they do, the overhead of needing to join to a massive table of postal codes means it just isn’t important. Nothing bad will happen if AB12 3CD is stored twice, or hell, even three times. There is little or no consequence in not adhering to the third level of normalisation in case like this – so little that it’s not often done. There’s no advantage in that degree of abstraction.

When working on our latest web CMS project, we decided we would not abstract our database layer so far as to not caring about what the database engine was and what flavour of SQL it used. We standardised on MySQL. Of course, we did abstract a lot of the functionality, but not to the extent where we were no longer using MySQL-flavoured SQL in our classes. We decided that we’d picked PHP and MySQL because the combination is highly performant and quick to develop for, so why bog it, and us, down with SQL translation for every single query.

The alternative would be to have dropped in something like PEAR DB, which we did consider for a while, as it would have enabled our app to be portable across an entire range of database platforms. However, I couldn’t stomach the thought of all that code (PEAR DB is big) even being parsed, let alone run for every database query (of which there are typically about a dozen per page load).

Instead, I opted for rolling my down, far simpler abstraction layer. Although our classes use MySQL-flavoured SQL, the only place that makes specific reference to any of PHP’s MySQL functions is the database class. We figured that if the worse came to the worse, it wouldn’t be too much effort to rewrite the database class to use a different engine if needs be.

The scalability / performance balance can be a difficult one to strike – especially is it’s not always apparent that you’re doing the wrong thing until you’ve done it. I’m pretty happy with the solution we settled on this time – but ask me again in six months’ time.

Update: Jeremy Zawodny expresses a view which pretty much confirms, in my mind, the decision we took. Zawodny’s a guy worth listening to.

- Drew McLellan

Comments

  1. § Goynang: Wouldn’t life be so much simpler if all the big database players supported the same SQL commands? Considering it’s supposed to be a standard SQL doesn’t half vary a lot!

    Recently I’ve been making heavy use of views to do a lot of the heavy lifting I might otherwise have done programatically in a page. This has sometimes meant doing some pretty database specific SQL but I figure if we ever need to swap over to another platform at least it’s all there in the view. So long as the view can be re-written (and indeed views are supported by the new platform!) then it would be pretty straightforward to recreate.

    I guess the same theory applies to stored procedures up to a point.
  2. § Jeremy: Maybe I’m missing something here, but isn’t your app scalable at this point? The design as you outlined it is scalable. The functionality may not be there yet, but there is a resonable path toward implementation of future funtionality.
  3. § Waccoon:

    @Goynang: That would be best, of course. Being able to write a database-level re-parser would be a HUGE benefit for everyone, given the simplicity of doing so.

    But, even free, open-source developers are often egotistical and not always interested in working with each other for the common good. Sad, but true. People always complain how fast the computer industry changes, but the fact is that a lot of programmers, especially UNIX developers, are often illogically traditional. Look at how little HTML has improved over the years, with a bumpy, bud-riddled ride the whole way.

    People should be focusing on making the tools behave as expected and as the task requires, rather than making layer after layer, trying to make all the different tools behave the same way.

Photographs

CSS Training Course: 18th July

We're running another CSS course aimed at beginners (or those wanting to freshen up!) on 18th July. Places are limited, so book soon to be sure of a place.

Work With Me

edgeofmyseat.com logo

At edgeofmyseat.com we build custom content management systems, ecommerce solutions and develop web apps.

Recent Links

Affiliation

  • Web Standards Project
  • Britpack
  • 24 ways

About Drew McLellan

Photo of Drew McLellan

Drew McLellan has been hacking on the web since around 1996 following an unfortunate incident with a margarine tub. Since then he’s spread himself between both front- and back-end development projects, and now is Director and Senior Web Developer at edgeofmyseat.com in Maidenhead, UK (GEO: 51.5217, -0.7177). Prior to this, Drew was a Web Developer for Yahoo!, and before that primarily worked as a technical lead within design and branding agencies for clients such as Nissan, Goodyear Dunlop, Siemens/Bosch, Caburys, ICI Dulux and Virgin.net. Somewhere along the way, Drew managed to get himself embroiled with Dreamweaver and was made an early Macromedia Evangelist for that product. This lead to book deals, public appearances, fame, glory, and his eventual downfall.

Picking himself up again, Drew is now a strong advocate for best practises, and stood as Group Lead for The Web Standards Project 2006-08. He has had articles published by A List Apart, Adobe, and O’Reilly Media’s XML.com, mostly due to mistaken identity. Drew is a proponent of the lower-case semantic web, and is currently expending energies in the direction of the microformats movement, with particular interests in making parsers an off-the-shelf commodity and developing simple UI conventions. He writes here at all in the head and, with a little help from his friends, at 24 ways.