That the Holy Roman Empire didn't "work" is a historical myth, and we can trace the origin of the myth pretty accurately. The Holy Roman Empire was pulled down partly by Prussia, and partly by revolutionary era France, and since the 19th century unification of Germany was the work of Prussia. it became a custom for German scholars to denigrate the Holy Roman Empire.
You can make the argument that there was no such country as "the Holy Roman Empire". The name was propaganda promoted by Barbarossa, in the twelfth century after the entity had been around. There was just the title "Roman Empire" that Charlemagne claimed. After the Treaty of Verdun, the title became associated with one of the successor kingdoms, the Kingdom of Italy, so whoever was King of Italy was also Roman Emperor.
What we call "the Holy Roman Empire" was the combination of three of the successor states of Charlemagne's empire, Germany, Italy, and Burgundy (Burgundy-Provence or southern Burgundy). The situation with Burgundy was really complicated and it lost all its territory by the middle of the fourteenth century, so it was Germany and Italy that was important. And medieval Germany worked as well or better as any other medieval kingdom. It had common institutions, defending itself from external enemies and expanded its territory, and internal conflicts were the sort of dynastic conflicts that every kingdom experienced. It had post-Reformation religious wars, including a really bad one after 1618, but so did everyone else. Germany only ran into problems when Friedrich II of Prussia started undermining it.
Italy, on the other hand, was in a state of anarchy even before Otto of Saxony showed up, and never developed national institutions, and the city states successfully resisted all attempts to establish them. Italy for some reason is included on maps showing the "Holy Roman Empire" before 1500 but disappears from later maps in historical atlases, with historians meaning just Germany when the talk about the "Holy Roman Empire" post Maximilian I, though there was no change in Italy's status.