It's supposed to be very unlikely, unless you're actively looking for trouble. In principle, patents are supposed to only be given out for inventions that pass a bar of novelty. If that were true (it often isn't), it should ensure that it's very very unlikely for others to arrive at the same patentable invention independently. If they do, tough luck to the second person.
Still, patents become public from the moment they are filed. So you can scour the patent applications database as well if you fear others have already filed for a patent for something you are trying to do. Of course, that will mean that, if you go ahead with your own implementation and the patent is later granted, you will not be able to claim that you didn't know about this, and will face higher damages if you end up in a lawsuit.
The principle here is that a company decides to publish some internal discovery instead of keeping it for themselves, and the government in return grants them a limited time monopoly on that invention. The company could instead keep the invention a secret, but in that case, they can't stop others from using it, and if someone else patents it, their secret invention can actually infringe on the patent granted to someone else later.
Still, patents become public from the moment they are filed. So you can scour the patent applications database as well if you fear others have already filed for a patent for something you are trying to do. Of course, that will mean that, if you go ahead with your own implementation and the patent is later granted, you will not be able to claim that you didn't know about this, and will face higher damages if you end up in a lawsuit.
The principle here is that a company decides to publish some internal discovery instead of keeping it for themselves, and the government in return grants them a limited time monopoly on that invention. The company could instead keep the invention a secret, but in that case, they can't stop others from using it, and if someone else patents it, their secret invention can actually infringe on the patent granted to someone else later.