You HAVE to get an ISBN before you publish. The ISBN is printed on the cover of the book. The printer has to know what it is before they can print copies. The only question is HOW LONG before you publish. In practice, you probably will spend at least a few weeks, and maybe months, getting the layout and cover design nailed down, reviewing proof copies and maybe making minor touch-up changes, etc. I guess it's possible to get an ISBN the day before you publish, then you slap it on to your cover design and go to print. More often it will be weeks or months.
You COULD get an ISBN years in advance, but as @MichaelKone says, the reason you give, worrying that someone else will use your title, probably just isn't worth worrying about. If your title is so generic that someone else might just happen to use the same words, "Introduction to Chemistry" or "The Soldier" or something like that, it's probably not a good title. If you're creative enough to write a book, you should be creative enough to come up with a distinctive title. (I don't think J K Rowling was worried that someone else might call their own book "Harry Potter and the Prisoner of Azkaban" just by shear chance.) I don't think there's anything in "the system" to prevent duplicate titles, so even if you get yours in first, someone else could still duplicate it.
As to where you get an ISBN: Each country has one organization that is the designated registrar for ISBNs in that country. In the U.S., for example, it's Bowkers. You have to find out who the registrar is in your country. If you are self-publishing, you can get your own ISBN, though most if not all companies that print your book will give you a free ISBN. If you are publishing through a mainstream publisher, they will certainly assign their own ISBN, and any that you buy will just be a waste of time.
BTW There are services out there that advertise that they will get an ISBN for you for a small fee. I cannot imagine how this is a useful service worth paying for. Instead of filling out the form from the real registrar, you fill out a form from somebody else that they than copy to the registrar's form, and they charge you to do this. It has to have all the same information or how could it be processed?