The terms "Top Dog" and "under dog" come from ship building.
When ships were made form wood, the long logs that were made into the decking were known as "dogs". To cut the logs or "dogs" to size a pit was dug and the log laid out across the pit, resting on the ground at each end. A large, double handed saw was then used to cut to size. Men worked in pairs on the saws. An older man and his apprentice. The more experienced man would stay on top, a much more pleasant place to be. He was the "Top Dog".
The young apprentice would be sent down the pit to saw from the bottom. He would be standing in rainwater, rats, rats piss, other workers piss (shipbuilders would piss into the pit), and the sawdust would be falling into his eyes constantly. A nasty place to work. He would be known as "The Under Dog".
And that's where we get the phrases Top Dog and Under Dog.