Sub topic 5
How the gateway connects to the Power BI service
This chapter assumes you know the difference between Import and DirectQuery datasets (semantic models) and can read a basic firewall rule. It also assumes you know that the Power BI service runs in the cloud while some data sources sit inside a company network. The chapter explains how the gateway bridges the two, which matters before you install one.
The core idea: the gateway calls out, nothing calls in
A data source on a corporate network is usually unreachable from the internet. The Power BI service cannot open a connection to sql01.contoso.local, and you would not want your firewall to allow it.
The gateway solves this by reversing the direction of the conversation. It is a Windows service running inside your network. It opens outbound connections to the cloud and keeps them open. When the service needs data, it leaves a request in the cloud. The gateway collects the request, runs it against the local source, and sends the answer back along the same outbound path.
The result is that you open no inbound ports and publish no data source to the internet. The firewall change is outbound only.
The components
| Component | Where it runs | Role |
|---|---|---|
| Power BI service (gateway cloud service) | Microsoft cloud | Receives refresh and query requests, builds the query, and holds the encrypted data source credentials |
| Azure Service Bus | Microsoft cloud | Carries requests to the gateway and responses back to the service |
| Gateway service | Your network | Opens the outbound connections, decrypts credentials, runs queries, and returns results |
| Data source | Your network | SQL Server, Oracle, a file share, or similar |
The Power BI service never talks directly to the data source. All traffic goes through the Service Bus channel that the gateway initiated.
What happens during a request
The same pattern applies to a scheduled refresh of an Import dataset and to a user opening a DirectQuery report.
- A trigger occurs. Either the refresh schedule fires, or a user interacts with a DirectQuery visual.
- The Power BI service builds the query. It attaches the data source credentials, encrypted so that only the gateway can decrypt them.
- The service places the request on a Service Bus queue.
- The gateway, which is already connected outbound, picks up the request.
- The gateway decrypts the credentials and connects to the data source.
- The data source runs the query and returns rows to the gateway.
- The gateway sends the results back through Service Bus to the Power BI service.
Step 1 happens once, when the gateway service starts, not once per request. That is why the gateway can answer a request seconds after it is queued without any inbound firewall rule.
Where the data goes
During a scheduled refresh, the gateway sends the result rows to the Power BI service, which stores them in the dataset. The data is compressed and encrypted in transit.
With DirectQuery, the data is not stored in the service. Each visual sends a query through the gateway and displays what comes back. This means every interaction with a DirectQuery report is a round trip through the gateway. A slow gateway machine or a slow network path is felt directly by report users.
Outbound ports and addresses
The gateway needs these outbound TCP ports:
| Port | Purpose |
|---|---|
| 443 | HTTPS to Power BI, Microsoft Entra ID (sign-in), and as a fallback for Service Bus |
| 5671, 5672 | AMQP to Azure Service Bus |
| 9350 to 9354 | Service Bus listeners |
The gateway prefers direct TCP connections to Service Bus, using the AMQP and 9350 to 9354 ports. If it cannot reach Service Bus that way, it falls back to HTTPS over port 443. That fallback works, but it is generally slower. Allowing the full port range gives better performance.
Port numbers are not enough on a firewall that filters by destination. The gateway also needs to resolve and reach the Microsoft endpoints involved. Microsoft publishes the current list of required addresses, which includes Power BI, Entra ID, and Service Bus names and changes over time. Treat the published list, not a copy in a runbook, as the source of truth.
You can check the ports from the gateway machine with PowerShell:
$ports = 443, 5671, 5672, 9350, 9351, 9352, 9353, 9354
foreach ($p in $ports) {
Test-NetConnection -ComputerName watchdog.servicebus.windows.net -Port $p |
Select-Object ComputerName, RemotePort, TcpTestSucceeded
}A TcpTestSucceeded value of False for the 9350 range with True for 443 means the gateway will work only in HTTPS fallback mode.
Testing connectivity from the gateway app
The on-premises data gateway app has a Network tab. It can run a test that checks the ports against the Service Bus endpoints for your installation, and it shows whether the gateway is using direct TCP or HTTPS. Run it after installation and again whenever a firewall or proxy changes.
The same tab has a setting to force HTTPS mode. Use it when the network team cannot open the AMQP and 9350 range, or when a proxy interferes with TCP connections. In that mode, all Service Bus traffic goes over port 443. Expect higher latency, which affects DirectQuery more than a scheduled refresh.
Proxies and TLS inspection
Many corporate networks route outbound traffic through a proxy, and the gateway honors proxy settings, but several problems recur:
- Proxy authentication. The gateway service runs under a service account, not under your user. A proxy that needs interactive sign-in or a per-user identity can block the service even though a browser on the same machine works.
- TLS inspection. Devices that decrypt and re-encrypt HTTPS can break the gateway's connections, because the gateway expects the certificate chain it would get from Microsoft. Exempt the required endpoints from inspection.
- Allow-listing by address. Cloud endpoint addresses change. A rule written once from an old list can fail months later.
Direction of each hop
It helps to keep these two paths apart when troubleshooting.
- Gateway to cloud: outbound only, over the ports above. Problems here make the gateway appear offline in the service.
- Gateway to data source: an ordinary connection on your internal network, such as TCP 1433 for SQL Server. Problems here appear as refresh errors on a gateway that is online.
The server and database names in the dataset must also match the gateway data source exactly, because the service uses them to map the dataset to that data source. For example:
let
Source = Sql.Database("sql01.contoso.local", "Sales"),
Orders = Source{[Schema = "dbo", Item = "Orders"]}[Data]
in
OrdersThe query above is Power Query M, not PowerShell, so the following block is the correct form:
let
Source = Sql.Database("sql01.contoso.local", "Sales"),
Orders = Source{[Schema = "dbo", Item = "Orders"]}[Data]
in
OrdersA later chapter covers the mapping step in detail. For now, remember that the gateway resolves sql01.contoso.local from its own machine. The name must be resolvable and reachable from the gateway, not from your laptop.
Common errors in this area
- Gateway shows offline after a firewall change. Outbound access to Service Bus was removed. Re-run the network test.
- Slow DirectQuery after moving the gateway. The gateway likely fell back to HTTPS mode. Check the Network tab.
- Works for you, fails on schedule. The test was run under your account and proxy, while the service account has a different path. Test as the service account.
- Inbound rule requested. Someone asks for an inbound rule to the gateway machine. None is required for Power BI traffic.
Exercise
A gateway machine can reach https://www.microsoft.com in a browser, and the gateway app shows "online" in the Power BI service. A scheduled refresh fails with an error that the data source is unreachable. Is the problem more likely on the gateway-to-cloud path or the gateway-to-data-source path, and why?
Show answer
Most likely the gateway-to-data-source path. An online gateway means the outbound channel to Azure Service Bus works, since the gateway could not report as online otherwise. The refresh error says the data source cannot be reached, so check name resolution, the internal firewall (for example TCP 1433 for SQL Server), and credentials from the gateway machine.
Exercise
Test-NetConnection to port 443 succeeds from the gateway machine, but ports 9350 to 9354 fail. Will the gateway stop working? What changes?
Show answer
The gateway will keep working, because it falls back to HTTPS over port 443 for Service Bus traffic. Performance is usually lower, which DirectQuery users notice most. To get direct TCP connectivity, ask the network team to allow outbound 5671, 5672, and 9350 to 9354.