The Simplest Way to Make IIS and Nats Work Like They Should
Running iis and nats together lets Windows web servers send fast messages to backend workers. IIS handles incoming web traffic, while Nats moves those events between internal services. This setup keeps user requests fast because the web server does not wait. Instead, the web app drops a task on a message subject and moves on. Backend workers pick up the message and finish the heavy work later. Teams use this pattern to connect older Windows apps with modern microservices. How data and keys fl
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Running iis and nats together lets Windows web servers send fast messages to backend workers. IIS handles incoming web traffic, while Nats moves those events between internal services.
This setup keeps user requests fast because the web server does not wait. Instead, the web app drops a task on a message subject and moves on. Backend workers pick up the message and finish the heavy work later. Teams use this pattern to connect older Windows apps with modern microservices.
How data and keys flow between iis and nats
In a standard setup, an IIS worker process runs your web app code. When a user clicks a button, IIS receives the web request first. The app inside IIS opens a persistent socket to the Nats server cluster. It needs a valid key, token, or certificate to log in to Nats.
Once logged in, the web app publishes a small payload to a specific subject. Nats checks the account rules to see if the app can write there. If the rule allows it, Nats routes the message to listening worker services. Those workers can also send a quick reply back to the IIS app.
Because IIS recycles worker processes on a schedule, socket management matters a lot. If an app opens a new socket for every web hit, ports run out. Good setups share one long-lived Nats client across the whole IIS worker process. When IIS recycles the pool, the app drains the connection before shutting down.
Common failure modes and how to scope access
Many teams make mistakes when they set up keys and network paths. The most common error is storing a single static Nats token on disk. Every app pool on the Windows server often reads that same local file. If one web site gets hacked, the attacker can read every message subject.
Broad permissions cause big problems in message systems too. Teams often let the web server publish and subscribe to all subjects with wildcards. A bug in one web app can flood internal topics or read private payloads. Silent errors also happen when teams skip audit logs on message writes.
End-to-End Encryption + NATS Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, give each IIS app pool its own distinct identity. Map each identity to a strict Nats account with narrow subject rules. Allow the web app to publish only to the exact subjects it needs. Block the web server from subscribing to backend admin subjects at all times.
Lock down the network path between the Windows host and the message cluster. Use firewall rules so only designated web hosts can reach the Nats port. Turn on TLS so no one on the network can read message payloads. Mask sensitive fields like emails, phone numbers, card numbers, or national IDs in logs.
Keeping worker pools and message clients healthy
Windows web servers manage memory and threads in their own unique way. When traffic spikes, IIS might spin up extra worker processes to share the load. Each new process will log in to the message server at the same time. Make sure your Nats connection limits account for these sudden worker pool changes.
Watch out for idle settings on your Windows host as well. By default, IIS shuts down worker pools when no web hits arrive. That pause closes the message socket until the next user visits the site. If your web app listens for background events, keep the worker pool running.
Always log when a worker pool starts, stops, or drops a message link. Clear logs help your team spot network drops before users notice slow pages. Test how your web app behaves when a Nats node restarts for updates. The client inside IIS should reconnect on its own without dropping user requests.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
How should an IIS app pool manage Nats connections?
Create one shared Nats client instance per IIS worker process when the app starts. Reuse that single connection for all web requests, and close it cleanly during pool shutdown.
Why do messages fail when IIS recycles a worker process?
If IIS kills the worker process too fast, buffered messages never leave the host. Flush the message client during the app shutdown event so pending writes finish first.
How can we limit what an IIS site does on Nats?
Assign a unique Nats user to each IIS app pool instead of sharing keys. Set subject rules so that user can only publish to specific queue names.
Related guides
In this post