How do different routing protocols (e.g., OSPF, BGP) work, and when would you use each in an enterprise network?

ServiceNowNetwork Engineer3–5 YearsNetworking

Routing protocols are essential for directing network traffic by exchanging route information between routers. The choice of protocol depends primarily on the network’s scale, whether it is an internal network or connecting to external networks, and the specific policy requirements. OSPF (Open Shortest Path First) and BGP (Border Gateway Protocol) are two of the most prevalent routing protocols, serving distinct roles in network architecture.

OSPF vs. BGP: Key Differences

OSPF is an Interior Gateway Protocol (IGP) designed for routing within a single Autonomous System (AS). It is a link-state protocol, meaning each router running OSPF maintains a complete topological map of the network within its AS. Routers use Dijkstra’s algorithm to calculate the shortest path to all destinations based on a cost metric, typically derived from interface bandwidth. OSPF converges quickly, making it ideal for dynamic internal network environments where rapid path recalculation is critical.

BGP, conversely, is an Exterior Gateway Protocol (EGP) used for routing between different Autonomous Systems, forming the backbone of the internet. It is a path-vector protocol, which means it exchanges full path information, including the sequence of ASes a route traverses, rather than just link-state data. BGP makes routing decisions based on a rich set of path attributes and policies, enabling sophisticated traffic engineering and adherence to business agreements between ASes. Its convergence is generally slower than OSPF due to its policy-driven nature and the vast number of routes it manages.

Best practice

The best practice is to deploy OSPF for internal routing within your enterprise network (your AS) to ensure fast convergence and efficient path selection. For connecting your enterprise network to the internet or to other independent organizations (other ASes), BGP is the appropriate choice. This combination provides a clear separation of routing concerns: OSPF handles the granular, rapid internal pathfinding, while BGP manages the broader, policy-driven inter-AS connectivity and traffic exchange with external entities like Internet Service Providers (ISPs).

Edge case interviewers probe for

Interviewers might ask about the use of iBGP (Internal BGP) within an AS, even when an IGP like OSPF is already present. This is a crucial edge case. iBGP is used to carry external BGP routes across the AS without having to redistribute them into the IGP, which can lead to routing loops or scalability issues. It ensures that all BGP speakers within the AS have a consistent view of external routes and can be leveraged for internal traffic engineering based on BGP attributes, allowing for more granular control over how traffic exits the AS, even from non-border routers.

Common mistake

A common mistake is failing to understand the primary purpose and scalability implications of each protocol. For instance, attempting to run OSPF across multiple independent organizations or using BGP as the sole internal routing protocol in a large, complex enterprise network. This either leads to unmanageable routing tables, poor performance, lack of policy control, or security vulnerabilities, as the protocols are not designed for those specific environments or scale.

What the interviewer is checking

The interviewer is checking your fundamental understanding of network hierarchy, the distinction between internal and external routing, and your ability to select the right tool for the job. They are assessing your knowledge of each protocol’s operational characteristics, scalability considerations, and how you would design a robust, efficient, and policy-compliant network that integrates both internal and external connectivity.

Imagine your company network is like a busy city, and you need to get mail from one building to another within that city. OSPF is like the city’s internal postal service. Every mail truck driver (router) knows all the roads, traffic conditions, and shortcuts within the city. They constantly share updates about blocked roads or new expressways, so everyone quickly knows the fastest way to deliver mail anywhere inside the city. It’s all about speed and knowing the exact path within your familiar territory.

Now, imagine you need to send mail from your city to another city, or even a different country. BGP is like the international shipping company that handles mail between completely different cities (Autonomous Systems). These companies don’t care about every street in your city; they care about the major highways connecting cities and the agreements between them. They pick routes based on factors like cost, reliability, and which other cities they have partnerships with, ensuring your mail gets across vast distances, even if it takes a slightly longer, more policy-driven path.

Why interviewers ask this

Interviewers ask this to gauge your foundational understanding of network architecture, your ability to differentiate between critical routing technologies, and your practical knowledge of when and where to apply each in a real-world enterprise environment. It tests whether you can design and manage network connectivity effectively.

What a strong answer signals

A strong answer signals not just theoretical recall but also practical network design acumen. It shows you understand the trade-offs, scalability considerations, and policy implications of each protocol, demonstrating the ability to make informed decisions for robust and efficient network operations.

Common follow-ups

  • Explain BGP path attributes and their influence on route selection.
  • How do route summarization and aggregation impact network performance and scalability in OSPF and BGP?
  • Describe a scenario where route redistribution between OSPF and BGP would be necessary and its potential challenges.

Advanced variation

Design a network for a multi-national corporation with several data centers and connections to multiple ISPs across different continents. Justify your choices for internal and external routing protocols, and detail your traffic engineering strategies for both inbound and outbound traffic, considering cost and performance.

A mid-sized company with multiple branch offices and a central data center decides to connect to two different Internet Service Providers (ISPs) for redundancy and improved performance. Initially, all internal routing within their offices and data center uses OSPF. To manage external connectivity to the two ISPs and control inbound/outbound traffic flow, the company implements BGP on its border routers. This allows them to advertise their public IP prefixes to both ISPs and use BGP attributes like AS_PATH prepending or LOCAL_PREF to influence which ISP traffic flows through, effectively enabling traffic engineering and failover mechanisms.

Company Network (AS 65001) Router A Router B Router C OSPF Border Rtr Internet (Various ASes) ISP 1 (AS X) ISP 2 (AS Y) BGP
  1. 1OSPF is an Interior Gateway Protocol (IGP) for efficient internal routing within a single Autonomous System (AS).
  2. 2BGP is an Exterior Gateway Protocol (EGP) used for inter-AS routing, connecting different networks on the internet.
  3. 3OSPF uses a link-state algorithm and calculates routes based on a cost metric, focusing on fast convergence.
  4. 4BGP is a path-vector protocol that makes routing decisions based on a rich set of path attributes and policies.
  5. 5Network design typically uses OSPF for internal network efficiency and BGP for external connectivity, traffic engineering, and policy enforcement.