The 2009-2010 iMacs were good in their time, although some are now starting to show problems particularly with video cards and displays that intermittently corrupt or black out. The 21.5-inch models weren't anywhere near as prone to failure and have proved to be a solid machine over time.
The 2011 iMacs weren't a bad machine, and only models with the AMD Radeon HD 6970M are affected by the common graphics issue. That card was powerful, but drew too much power and ran too hot for the thermal management inside the iMac enclosure, hence their high failure rate. The base model 27-inch iMacs with AMD Radeon HD 6770M graphics used less power and produced a fraction of the heat, and as such are actually one of the more reliable models. Outside of the usual hard drive failures that come with any machine, I haven't seen many of them come in for service.
The 21.5-inch 2011 iMac is probably the most reliable, with many still in active service but almost none coming in for repairs. As a matter of fact, I don't think I've ever seen a 21.5" 2011 come in for major repairs, period!
The 2012-current models aren't terrible, but there are some things to watch out for. 27-inch models will most likely develop issues with the hinge mechanism if they haven't already, where the screen suddenly drops down and refuses to hold its vertical tilt. Apple is still covering this issue, but not with a revised part, so I expect to see these machines in again and again. Early models with 3TB hard drives often develop drive issues and were once covered under a replacement program, however as this program has now ended, any failures will be a paid repair.
The 21.5-inch 2012 onward models aren't affected by either issue, as their lower overall weight places less stress on the mechanism, and none came with a 3TB internal drive as they use 2.5-inch hard drives instead.
The common trend is that 21.5" models seem to last longer than their 27-inch counterparts, usually due to their lower relative performance and the lower stresses on components that comes with it. I recommend these models to anyone that isn't specifically looking for the larger screen. The 2011 machine is still a good purchase that can be had for a reasonable price, even for the larger screen 27-inch model, as long as you avoid models with the Radeon 6970M graphics. I wouldn't pay a ridiculous amount for one mind you, most people I see coming in with second hand purchases are spending between $700-$900 for them, and for a standard configuration in working condition, that's about the most I would pay. Additional RAM and maybe an SSD would perhaps warrant a higher price, but ultimately that's up to the buyer.