The appearance of gold in 1848 would make their continuing independence difficult. First, a lot of Americans would have made their way there to panhandle. As the population increases there would probably be a natural tendency to look to the US. Second, I think the US would have been hard pressed to put aside manifest destiny just because someone declared independence from Mexico. Also, California would have been an inviting target for Nappy while he was meddling in Mexico. These things probably push it into the US. Finally, looking further out, San Diego, Los Angeles, and San Francisco each have important ports. If the US loses those, it has only Seattle to fall back on. Any eventual Pacific ambitions are scaled back by not having those ports.
California's geography would make it hard to conquer if it required invasion. But I am not sure the "Republic of California" would have been able to organize itself in such a way to create an adequate defense. It certainly would have required arms imports. The British? The Russians? After the Civil War, the union army could have rolled on whatever existed.