Most adventures I run are optimized, in that I present the party with multiple threats/things going on in nearly every encounter or scenario, so most of the time is spent with them scouting, running around, figuring out what to do, and getting caught in hilarious situations like watching their friends walk into a trap but not being able to do anything about it.
I've always done this. I think it's because i'm either good at eyeballing sheets to know what my parties can handle, or because I create realistic enemies/organizations and don't metagame.
At a higher level of play and optimization... honestly it comes down to just not having DMPC BBEGs that you care about, and not having cookie cutter railroad plotlines. As long as you realize that there's very little your PCs can't dismantle given time, you can create all kinds of things for them to rip to pieces, and then chuck time pressure and personal relationships and deep plots and unexpected things that give them a minor heart attack ('he uses DARK SPEECH ON THE SWARM?!?') on top to be the actual challenge, and it works really well. You can kill PCs at any time, you're the DM, that's not the point. Just realize that a T-Rex in a room isn't actually going to be a challenge for your level 11 PCs, and that to actually challenge them you need to be sneakier or simply overload them and force them to make real decisions (where to go, whether to use their last spells or not, save the girl their character is crushing on or the world... and the threat to the world might not be real, etc etc)... and it's really easy to run games even with TO material in it.
Of course a very basic part of this is realizing that the CR system is a piece of crap and being able to judge the capabilities of PCs from their character sheets.
I am very confident that even in a game with metanode casters and dusk giant two-step martial monks, I could challenge the party. Hell, it would probably be easier, they'd likely want to do their own thing a lot more and give me all kinds of hooks to drop shit on them from.