How can hard drives store so much data and before it fails, be so reliable to give back all the bits without any error?
Solution 1:
Tons of reasons, many of which are far too complex for me to even understand. They're shielded from electromagnetic radiation (well, background levels anyway), and contained in a sealed, dust free container.
As for error handling:
Error handling
Modern drives also make extensive use of Error Correcting Codes (ECCs), particularly Reed–Solomon error correction. These techniques store extra bits for each block of data that are determined by mathematical formulas. The extra bits allow many errors to be fixed. While these extra bits take up space on the hard drive, they allow higher recording densities to be employed, resulting in much larger storage capacity for user data. [14] In 2009, in the newest drives, low-density parity-check codes (LDPC) are supplanting Reed-Solomon. LDPC codes enable performance close to the Shannon Limit and thus allow for the highest storage density available. [15]
Typical hard drives attempt to "remap" the data in a physical sector that is going bad to a spare physical sector—hopefully while the number of errors in that bad sector is still small enough that the ECC can completely recover the data without loss. The S.M.A.R.T. system counts the total number of errors in the entire hard drive fixed by ECC, and the total number of remappings, in an attempt to predict hard drive failure.
From here.
The rigidity of the innards and the fact it's a sealed, solid unit means small vibrations shouldn't create a bad write, though it can happen to potentially quite disastrous results. It uses the air pressure inside the sealed container to keep things running smoothly. Things go wrong quite often, even with ECC, which is partly the reason for hard disk recovery tools, redundancy and the like.
Solution 2:
You can do even worse things with external hard disks, and they will still work.
Although it's not a good idea to move such a disk while rotating, I have been doing this without any problem. I even dropped on the floor such disks (more than once) while still rotating, with no ill effects. Even external disks that were just old internal disks mounted in an enclosure.
So I can testify that disks are constructed as resistant to minor (and maybe more than minor) shocks.