Usually, for this particular scenario, I try to max both Defenses to get them as close as possible and it works well for me. So, for instance, if both Defenses have the same base stat, I would invest 252 HP/180 SpD/76 Def. Then, I give it a Defense boosting nature and this maximizes the Defenses on both sides of the spectrum. This gets the Defenses within 1 Point of each other. This is for a mixed wall. For a Staller, it is the same thing. However, there are plenty of exceptions like Chansey and Blissey. Now for a Tank, this depends on what it is. For instance, if it is a Special Tank, there are many options that depend on what you want. Let's assume you do 252 SpA first. If you want to maximize its Special Bulk, you can do 252 SpD, but if you want to give it some range in the Physical Spectrum, you can do 252 HP. So, it really depends on what you want. I usually run 252 HP for some Physical Bulk, but really, both work.
1. I would go 252 HP/60 Def/196 SpD with a Bold Nature. While this does stray from what I said earlier, you shouldn't try to just maximize both Defense blindy. You should shape it with your typing and the current Meta. I usually let the Defense be slightly more to help with Alakazam's Psyshock, coverage Earthquake along with Pokémon like Urshifu, Dragapult and others.
2. With Melmetal, I agree with Smogon here. I always prefer HP because you maximize bulk on both sides, especially with an Assault Vest. While you can choose to differ from what I said here, but I still prefer HP over a Defense. However, if you didn't have an Assault Vest, I would go 252 SpD.
3. With Ferrothorn, I would run run 252 HP/56 Def./200 SpD with an Impish Nature. I would again lean to make the Defense stat slightly higher, especially with that Fighting weakness. Nothing will patch that Fire weakness. This still maximizes your longevity in Battle in my opinion. You may choose to differ if you wish.
4. For me, it depends again in what you want. I am assuming you are talking about something like Melmetal here. If you want a Physical Tank, put 252 HP or Defense to make it as Bulky as possible. Now, I would never do 128 On each Defense in this case. In my opinion, you either go all one way or another. If you want to maximize its bulk on both sides, I would go 252 HP or Special Defense, preferably the latter in this Scenario. I regret that I can't give you a conclusive answer On this one, but it is truly your choice.
Hope this helps!