In 5e, you just shoot in melee - you have disadvantage, but you can do it, and it's not an added danger over and above regular melee. It's not realistic, of course, neither are a lot of things.
It strikes me mainly as a compromise for playabilty and to make the game less tactically challenging or frustrating - faster combat, too. I suspect it'd be OK in many other settings, too, even a little less unrealistic to shoot a gun in the middle of a fist fight with just Disadvantage, than a bow, even.
The assumption here, is, I assume, some sort of 'fair fight' scenario with a similar-level character-classed enemy or CR monster. Yeah, those fights aren't over instantly. OTOH, if a bunch of much lower-CR creatures charge you across on open field, you'll be able to drop some of 'em - possibly as many as you can loose arrows in the time you have.
Levels & hps fundamentally change how arrows, knives, swords, and being immolated work in D&D compared to RL, too.
While there's /plenty/ of close combat in a typical western or modern action adventure, the point about suppression is worth thinking about. D&D declines to model a /lot/ of viable tactics, both medieval and modern, at least, formally. (At some points, it did handle things like suppressions, but they were modestly obscure and not around long.)
A 5e DM could always go all "goal & method" on suppression fire, though: The player says "I snap off shots to keep their heads down" and the DM tells him to mark off X rounds, and narrates those enemies staying behind cover that round (or has the targets make WIS saves vs a DC based he comes up with, those who fail stay hunkered down - he chooses other actions for those who make it).
Well, the player can decide to have the PC do that, whether the PC thinks he's safe or not is a matter of RP, and whether any of his enemies think there's no way they could have killed him is up to the DM.