How to know when you need a Custom Drupal module
At the time I'm writing this, there are 15,708 contributed modules available on drupal.org. Even if you filter that down to full projects available for Drupal 7, you still have a staggering 3809 modules to sort through. With all of those modules available, you'd like to think that there's a module for everything under the sun, and you wouldn't be far from the truth (you can even make it snow in winter if you like). But even with all of those choices out there, it's rare that I'll build a site without finding a use for at least a small module or two. With that in mind, if you've scoured drupal.org and can't quite find what you're looking for, here are some examples of the types of situations where it might be time to go custom.
Performance Issues
Very often in the Drupal world, modules are built to be as general purpose as possible. This is an excellent thing and one of the biggest reasons why I love Drupal so much. However, this can also mean loading up a few thousand extra lines of code for just a small feature on your site. Of course, not all lines of code are created equal, and a module on drupal.org (contrib module) built with caching and performance in mind may outperform a module one tenth its size. Still, if you're concerned with performance (and you should be), limiting the number of modules used on a site is often a good thing, and writing code that is finely tuned to your exact web site will generally be more efficient than the general purpose solution available elsewhere.
Glue modules
Another common situation when building a site is when you install two or three modules that all sound like they'll work together perfectly and do exactly what you need, but then something doesn't quite fit. Sometimes there's another module out there that works better, but sometimes you're just trying to do something a little different than any of the developers had thought of and things just won't quite come together. Enter the glue module. These are often very short custom modules which simply cajole all the moving parts together so that they do what you want. I've literally written modules that were about 5 (functional) lines of code that made the whole site come together.
Tweak modules
Much like a glue module, tweak modules tend to be very short and focused and make some kind of minor adjustment to the site that is just not possible on a configuration screen. The only difference between this and a glue module is that instead of trying to bring a few modules together, you're usually doing something straight forward like making breadcrumbs function how you want them to or handling very site specific things like a custom redirect. As a rule of thumb, if you say to yourself "this should be so easy, why can't I figure out how to do this?", it may be you just need to call a special hook function in a custom module, do a little tweak, and be on your way.
Custom Functionality
The final case where I see custom modules needed is the most obvious but also the most complicated. When there just isn't a module out there that offers the features you're looking for, it has to be written. A word of caution here though, there are a lot modules on drupal.org that can be used in ways that are not immediately obvious. My favorite example of this is the Flag module. Want an easy way to report abuse? how about site bookmarks? A playlist? Maybe a way for an administrator to mark a sale as paid? The flag module doesn't tell you all the things you can use it for, but it's a general purpose tool that does a lot. So, before you fire up your code editor (or worse yet, paying someone else to fire up theirs), make sure there isn't a good general purpose solution that will fit the bill.
Final words of wisdom
There are a lot of good reasons why sites need custom modules, but if you're working with a developer or you are a developer whose first solution to everything is to start writing code, then you should be concerned. One of the major benefits of using open source software is that it's constantly being developed, and if you can go with a contrib module, there's a good chance your site will get new features down the road for free. You won't get that if you're maintaining your own custom modules. Not only that, but contrib modules that are well used are also well tested. This means a lot of eyes have looked at the code and a lot of people have used it and reported bugs. If it's a more popular module, that should help you sleep better at night. Finally, modules up on drupal.org are going to be more scrutinized for security problems, and that's a good thing to. I did a quick repair on a client site recently and discovered some very dangerous security holes that without a relatively simple fix left their site wide open to intruders. A custom module of course needs to keep security in mind as well, and if you're not certain that it does, you might be better off again in contrib.
var switchTo5x = true;stLight.options({"publisher":"dr-53823897-181c-4461-ae09-5adff87aeeb"});