Understand the boundaries and execution flow differences between AEM Author, Publish, Dispatcher, and CDN.
AEM - Code Execute flow
Problem statement
Just because code runs on Author doesn't mean it will run correctly on Publish. Do you know the boundaries between these environments?
Note: Sling/Java code still executes on Publish. A CDN like Cloudflare does not execute Sling code; it only caches and serves the responses generated by the Publisher.
Code Execution Flow
- Publish Environment
- Author Environment
If a request hits the Publisher, Java code will execute. If a request is served directly from the Dispatcher or CDN cache, Java code will not execute.
Separation of Concerns Across 4 Layers
1. Java / Sling Correctness
Code must run independently on Publish. Check: Sling Models, Servlets, OSGi Services, Schedulers, Event Handlers, ResourceResolvers, and Service Users.
Do not rely on conditions or paths that only exist on Author.
Example:
or
These paths or nodes might not exist on Publish.
Just because Author has resources at:
does not mean Publish has them.
2. Author vs. Publish Content
Author and Publish instances have separate JCR repositories.
Example:
Author initial state:
You update it to:
Author reflects the change immediately, but Publish will still show title = "Hello" until the page is published/replicated.
3. Dispatcher Security & Filters
Example:
- Author directly:
http://localhost:4502/bin/productworks. - Publish directly:
http://localhost:4503/bin/productworks. - Through Dispatcher:
https://site.com/bin/productreturns403or404.
Reason: The Dispatcher filter blocks requests by default:
and /bin/product has not been explicitly allowed yet.
4. CDN & Caching
The caching chain is: Cloudflare (CDN) -> Dispatcher -> Publisher. If content is cached at the CDN or Dispatcher level, requests won't hit the Publisher, so cache invalidation/flushing is required when updating dynamic logic or content.
Tips & Best Practices
- Add request-correlated logging during development: