It could be argued that every Canadian investor should have some exposure to railways as part of a diversified portfolio. After all, they have one of Warren Buffet’s key criteria for evaluating a stock—a wide economic moat.

Both Canadian National Railway Company (TSX:CNR)(NYSE:CNI) and Canadian Pacific Railway Company (TSX:CP)(NYSE:CP) are protected by massive barriers to entry due to the complexity of getting right of ways across massive distances, and it is for this reason that no new mainlines are likely to be built in North America.

This does not mean there aren’t risks, however. The recent across-the-board plunge in commodity prices presents a massive risk to railways, and there are several reasons why investors who are concerned with these risks should consider investing in CN over CP. The share prices speak for themselves—CN is only down 4.5% throughout this year’s market turmoil, compared to 11% for CP.

CP is heavily exposed to both coal and grain

Most railways operate in three areas—bulk, merchandise, and intermodal. Bulk commodities refer to things like coal, grain and fertilizers, which move in large volumes across large distances.

CP is currently focused on bulk transportation, with 41% of their business mix devoted to it, compared to a fairly low 22% for CN. About 52% of CP’s bulk revenues come from grain transportation, with 23% coming from coal and the remainder from fertilizer.

In other words, CP is a heavily grain- and coal-focused business, and this presents a large degree of risk. About 90% of CP’s coal business comes from serving one customer—Teck Resources (TSX:TCK.B)(NYSE:TCK)—which produces metallurgical coal that is largely exported overseas and used in steel-making.

The problem is that Teck’s largest customer is China. Due to the recent slowing of the Chinese economy as it transitions from an investment-focused economy that uses plenty of steel to a consumer-spending-focused economy that does not, China has seen its demand for Teck’s coal drop dramatically.

The end result is metallurgical coal prices recently hit a 10-year low, and the market is deeply oversupplied—Teck estimates by 10-15 million tonnes—and as a result Teck began implementing rotating shutdowns of its six Canadian mines in Q3 2015. Teck’s CEO has indicated a production cut may be in the cards in the fourth quarter if production does not improve.

What does this mean for CP? In general, it means lower volumes and lower revenues. Grain will also present a continued headwind for CP, with Statistics Canada expecting Canadian grain production to be down 15% year over year in 2015, with continued weakness in 2016.

While CN is also exposed to grain and coal, they represent a much smaller portion of CN’s overall business mix. CN’s business model is better balanced among all business segments, which means CN is not overly dependent on one area. The benefits of this diversification were evident in Q2 2015, when CN posted stronger results.

CN has a stronger intermodal business than CP, which reduces risk

Intermodal transportation refers to the transportation of largely retail goods in specialized containers that can be moved by ship, train, or truck. CP gets about 22% of revenues from intermodal, whereas CN gets about 23%, and while those numbers are close, CN’s intermodal business is higher quality.

Intermodal is an important diversifier and source of growth. It allows CP and CN to access consumer spending both overseas and in North America since intermodal largely transports retail goods. In this regard, CN has an advantage because its rail system has access to the west coast, the east coast, as well as the Gulf of Mexico. CP’s rail network does not extend much further south than Chicago.

The result is that CN has much better cross-border exposure than CP, which exposes CN to U.S.-bound import traffic driven by the relatively strong U.S. economy, which is poised to continue improving.

CN also has a much stronger international intermodal business, and is the primary service provider to 16 of the 19 shipping companies that call at Canadian ports.

Overall, CN's better diversification make it a safer play, while still retaining growth prospects thanks to its exposure to the U.S. economy. If you're looking for more direct exposure to the U.S. economy, consider buying U.S. stocks directly.

3 U.S. stocks EVERY Canadian should own

Looking to expand your portfolio's horizons? The Motley Fool has put together a special FREE report featuring "3 U.S. Stocks Every Canadian Should Own." To get the names and ticker symbols of these three stocks, just click here to access your free copy!

NEW! This Stock Could Be Like Buying Amazon In 1997

For only the 5th time in over 14 years, Motley Fool co-founder David Gardner just issued a Buy Recommendation on this recent Canadian IPO.

Stock Advisor Canada’s Chief Investment Adviser, Iain Butler, also recommended this company back in March – and it’s already up a whopping 57%!

Enter your email address below to claim your copy of this brand new report, “Breakthrough IPO Receives Rare Endorsement.”

Fool contributor Adam Mancini has no position in any stocks mentioned. David Gardner owns shares of Canadian National Railway. The Motley Fool owns shares of Canadian National Railway. Canadian National Railway is a recommendation of Stock Advisor Canada.