The first Chinese immigrants arrived in San Francisco in the 1840s due to poverty in China and to work on the transcontinental railway. They faced significant racism and discrimination from Americans, including taxes and restrictions on marriage and citizenship. This led the Chinese to establish Chinatowns for safety and community. While Chinatowns faced early hardships, the one in San Francisco remains a prominent tourist area today with hundreds of Chinese restaurants and shops.