The northern states fought against the southern states in a civil war between 1861 and 1865. The industrialized north finally won, defeating the southern Confederacy. One of the main issues was slavery. The southern states wanted to break away from the north and continue to use slavery. The north was antislavery.
During wartime a country's industry and agriculture are disrupted. At the same time they have an army of men they need to feed and clothe. Canada enjoyed a boom in its economy during the war, because our products were needed by the Americans and our trade greatly increased.
There was also a war in Europe at the time, the Crimean War, which increased the demand for Canadian goods even more.
After the Civil War, though, Canadians began to fear that the victorious northern states would turn their armies on Canada. Britain had supported the south during the war and Canadians expected retaliation for that. Also, there was a vocal movement in the States which claimed that it was their country's Manifest Destiny to control all of North America.
These fears increased the motivation of Canadians to unite. They also spurred on railway building plans as Canada hastened to lay claim to the vast western plains.