SlideShare a Scribd company logo
Caching Up is Hard To
Do
Chad McCallum
ASP.NET MVP
iQmetrix Software
www.rtigger.com - @ChadEmm
Improving the performance of your web
services
Here’s your API
Client makes a request Bounces around the
internet to web server
Web server runs
application, queries DB
Database returns data
from query
Application serializes
response and writes to
client
Bounces back through
internet to client
Client receives data
Client The Internet Web Server Database
An example request
Client The Internet Web Server Database
Client makes a request Bounces around the
internet to web server
Web server runs
application, queries DB
Database returns data
from query
Application serializes
response and writes to
client
Bounces back through
internet to client
Client receives data
270ms
598ms3474ms
4342ms
528kb
Start at the data
• Optimize the database server
• Logical Design – efficient queries, application-specific schema, constraints,
normalization
• Physical Design – indexes, table & system settings, partitions, denormalization
• Hardware – SSDs, RAM, CPU, Network
Between your App and the Data
• Reduce the complexity of your calls – get only the data you need
• Reduce the number of calls – return all the required data in one query
• Make calls async – perform multiple queries at the same time*
• The fastest query is the one you never make
• Cache the result of common queries in an application-level or shared cache
598ms 315ms
47%
Application Time
Caching Data
• Great for static or relatively unchanged data
• Product Catalogs
• Order History
• Not so great for volatile data
• Store Quantity
• Messages
• Comes with a memory price
• Shared Cache when working with a web farm
Inside your App
• Standard “MVC” Flow
• Request comes into Web Server over network connection
• Framework parses request URL and other variables to determine which
controller and method to execute, checking against routes
• Framework creates instance of controller class and passes copy of request
object to appropriate method
• Method executes, returning an object to be sent in response
• Framework serializes response object into preferred type as requested by
client
• Web server writes response back to client over network connection
Inside your App
• The most we can reasonably do is optimize our controller’s method
• “Reasonably” meaning not doing crazy things to the underlying framework
code / dependencies
• The fastest method is one you don’t execute
• Cache the serialized result of common API calls
598ms 296ms
51%
Application Time
Caching Responses
• Great for endpoints that don’t take parameters
• Get
• Not so great for endpoints that do take parameters
• Get By ID
• reports with date ranges
• Get with filters
• Cache all supported serialization formats
• Same cache concerns – memory usage, shared cache in farm setup
From Server to Client
• We can’t really change the topology of a client’s network connection
• We can send less data
• HTTP Compression
3474ms 1083ms
69%
528kb 129kb
76%
Response Size Response Time
HTTP Compression
• Trading response size for server CPU cycles
• Output can be cached (and often is) by web server to avoid re-
compressing the same thing
• Client requests compression using Accept-Encoding header
598ms 624ms
4%
Application Time
Paging
• Don’t send everything!
• Only returning 20 items
• Page objects using OData Queries in WebAPI
• Returning IEnumerable<T> will page in-memory
• Returning IQueryable<T> will (attempt to) page at the database layer
3474ms 7ms
99.8%
528kb 10kb
98.1%
Response Size Response Time
Conditional Headers
• Server can send either an ETag and/or Last-Modified header with
response
• ETag = identifier for a specific version of a resource
• Last-Modified = the last time this resource was modified
• Clients can include that data in subsequent requests
• If-None-Match: “etag value”
• If-Modified-Since: (http date)
• Server can respond with a simple “304 Not Modified” response
Conditional Headers
3474ms <1 ms
99.9%
528kb 0.3kb
99.9%
• Avoid database calls to validate requests
• Cache last modified times & etag values
• May have to modify client code to retain and send Last-Modified and
ETag values
• Most browsers will automatically include If-Modified-Since, but some do
not include If-None-Match
• Non-browser code (SDKs, WebClient, HttpClient)
Response Size Response Time
598ms 323ms
54%
Application Time
Client-Side Caching
• Most browsers have a local cache – tell your clients to use it!
• Expires header tells client how long it can reuse a response
• Expires: Thu, 03 Apr 2014 03:19:37 GMT
• Cache-Control: max-age=## (where ## is seconds) header does the
same, but applies to more than just the client cache…
• In either case it’s up to the client whether it uses the cache or not
• Most browsers cache aggressively
Intermediate Caching
• Cache-Control header specifies who can cache, what they can
cache, and how things can be cached
• Public / Private – whether a response can be reused for all requests, or is
specific to a certain user
• max-age – the longest a response can be cached in seconds (overrides Expires
header)
• must-revalidate – if the response expires, must revalidate it with the server
before using it again
• no-cache – must check with the server first before returning a cached
response
Client-Side Caching
• Great for static or relatively static data
• Static HTML, JS, CSS files, or read-only lists of data that rarely change
• Not so great for dynamic or mission-critical data
• Hard to force clients to get latest version of data when they don’t even talk to
the server
• If you have to update before Expires or Max-Age runs out, you’ve got a
problem
4342ms 100ms
97.7%
Response Time
Review
• Optimize your database for your application
• Cache on the server
• Common database calls
• Serialized results
• Send less data
• HTTP Compression
• Paging
• Conditional Headers / 304 Not Modified
• Cache on the client
• Expires and Cache-Control headers
Abracadabra!
4342
100
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
Milliseconds
Before After
Chad McCallum
www.rtigger.com
@ChadEmm

More Related Content

What's hot (20)

PDF
How to boost performance of your rails app using dynamo db and memcached
Andolasoft Inc
 
PPTX
Azure database services for PostgreSQL and MySQL
Amit Banerjee
 
PDF
Azure API Manegement Introduction and Integeration with BizTalk
Shailesh Dwivedi
 
PPTX
Tips for Optimizing Web Performance
ThousandEyes
 
PPTX
Closing the door on application performance problems
ManageEngine, Zoho Corporation
 
PPTX
Leveraging ApsaraDB to Deploy Business Data on the Cloud
Oliver Theobald
 
PPTX
Cloud Design Pattern part2
Masashi Narumoto
 
PPTX
10 performance and scalability secrets of ASP.NET websites
oazabir
 
DOC
How to improve your apache web server’s performance
Andolasoft Inc
 
PPTX
Key to optimal end user experience
ManageEngine, Zoho Corporation
 
PPTX
What SQL DBAs need to know about SharePoint
J.D. Wade
 
PDF
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
.NET Conf UY
 
PPTX
DDD and CQRS for .NET Developers
Allan Mangune
 
PPTX
Modern Cloud Fundamentals: Misconceptions and Industry Trends
Christopher Bennage
 
PPT
Web Servers (ppt)
webhostingguy
 
PPTX
Azure SQL Managed Instance - SqlBits 2019
Jovan Popovic
 
PDF
(ATS6-PLAT09) Deploying Applications on load balanced AEP servers for high av...
BIOVIA
 
PPTX
Optimizing Data Management for MongoDB
Imanis Data
 
PDF
Using Dockers for DB Monitoring
Prasad Raghuram Vemuri
 
PDF
Monitoring CDN Performance
ThousandEyes
 
How to boost performance of your rails app using dynamo db and memcached
Andolasoft Inc
 
Azure database services for PostgreSQL and MySQL
Amit Banerjee
 
Azure API Manegement Introduction and Integeration with BizTalk
Shailesh Dwivedi
 
Tips for Optimizing Web Performance
ThousandEyes
 
Closing the door on application performance problems
ManageEngine, Zoho Corporation
 
Leveraging ApsaraDB to Deploy Business Data on the Cloud
Oliver Theobald
 
Cloud Design Pattern part2
Masashi Narumoto
 
10 performance and scalability secrets of ASP.NET websites
oazabir
 
How to improve your apache web server’s performance
Andolasoft Inc
 
Key to optimal end user experience
ManageEngine, Zoho Corporation
 
What SQL DBAs need to know about SharePoint
J.D. Wade
 
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
.NET Conf UY
 
DDD and CQRS for .NET Developers
Allan Mangune
 
Modern Cloud Fundamentals: Misconceptions and Industry Trends
Christopher Bennage
 
Web Servers (ppt)
webhostingguy
 
Azure SQL Managed Instance - SqlBits 2019
Jovan Popovic
 
(ATS6-PLAT09) Deploying Applications on load balanced AEP servers for high av...
BIOVIA
 
Optimizing Data Management for MongoDB
Imanis Data
 
Using Dockers for DB Monitoring
Prasad Raghuram Vemuri
 
Monitoring CDN Performance
ThousandEyes
 

Viewers also liked (16)

PPTX
Ready, set, go! An introduction to the Go programming language
RTigger
 
PPTX
Windows 8 programming with html and java script
RTigger
 
DOC
Aruna Kumar_Resume
Arun Kasaraguppe
 
PPTX
Open regina
RTigger
 
PPTX
Open source web services
RTigger
 
PPTX
How to hire a hacker
RTigger
 
PPTX
You Can't Buy Agile
RTigger
 
PPTX
Single page apps and the web of tomorrow
RTigger
 
PPTX
Async in .NET
RTigger
 
PDF
E government solution by cotsys version 1-5
COTSYS LTD
 
PDF
Seamless Integration of Data in E Government
WSO2
 
PPTX
Modernization Of State Government Treasury
Anirban Mukerji
 
PDF
Biometric identification
Bozhidar Bozhanov
 
PPTX
E-government architecture
Bozhidar Bozhanov
 
PPT
e-governance
namitmalhotra21
 
PDF
Huawei Solutions for Smart Cities
Muhammad Rauf Akram
 
Ready, set, go! An introduction to the Go programming language
RTigger
 
Windows 8 programming with html and java script
RTigger
 
Aruna Kumar_Resume
Arun Kasaraguppe
 
Open regina
RTigger
 
Open source web services
RTigger
 
How to hire a hacker
RTigger
 
You Can't Buy Agile
RTigger
 
Single page apps and the web of tomorrow
RTigger
 
Async in .NET
RTigger
 
E government solution by cotsys version 1-5
COTSYS LTD
 
Seamless Integration of Data in E Government
WSO2
 
Modernization Of State Government Treasury
Anirban Mukerji
 
Biometric identification
Bozhidar Bozhanov
 
E-government architecture
Bozhidar Bozhanov
 
e-governance
namitmalhotra21
 
Huawei Solutions for Smart Cities
Muhammad Rauf Akram
 
Ad

Similar to Caching up is hard to do: Improving your Web Services' Performance (20)

PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
PDF
Clug 2012 March web server optimisation
grooverdan
 
PDF
Web performance mercadolibre - ECI 2013
Santiago Aimetta
 
PDF
Asp.net caching
Mindfire Solutions
 
PDF
API Caching, why your server needs some rest
Luis Cipriani
 
PPTX
Caching
saravanan_k83
 
PDF
Web performance optimization - MercadoLibre
Pablo Moretti
 
PPTX
Web Caching Systems improve web performance by storing frequently accessed re...
Muhammmad Naveed
 
ODP
Clug 2011 March web server optimisation
grooverdan
 
PPTX
Cache is King
Steve Souders
 
ODP
Caching Strategies
Michal Špaček
 
PPTX
Caching Up and Down the Stack
Dan Kuebrich
 
PPT
Jax Ajax Architecture
Alois Reitbauer
 
PPT
Web Speed And Scalability
Jason Ragsdale
 
PPTX
The Most Frequently Used Caching Headers
HTS Hosting
 
PDF
Caching in HTTP
Alexander Shopov
 
PDF
ASP.NET Scalability - NxtGen Oxford
Phil Pursglove
 
PDF
ASP.NET Scalability - WebDD
Phil Pursglove
 
PPTX
HTTP Caching.pptx
Md. Rakib Trofder
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
Clug 2012 March web server optimisation
grooverdan
 
Web performance mercadolibre - ECI 2013
Santiago Aimetta
 
Asp.net caching
Mindfire Solutions
 
API Caching, why your server needs some rest
Luis Cipriani
 
Caching
saravanan_k83
 
Web performance optimization - MercadoLibre
Pablo Moretti
 
Web Caching Systems improve web performance by storing frequently accessed re...
Muhammmad Naveed
 
Clug 2011 March web server optimisation
grooverdan
 
Cache is King
Steve Souders
 
Caching Strategies
Michal Špaček
 
Caching Up and Down the Stack
Dan Kuebrich
 
Jax Ajax Architecture
Alois Reitbauer
 
Web Speed And Scalability
Jason Ragsdale
 
The Most Frequently Used Caching Headers
HTS Hosting
 
Caching in HTTP
Alexander Shopov
 
ASP.NET Scalability - NxtGen Oxford
Phil Pursglove
 
ASP.NET Scalability - WebDD
Phil Pursglove
 
HTTP Caching.pptx
Md. Rakib Trofder
 
Ad

More from RTigger (12)

PPTX
Give your web apps some backbone
RTigger
 
PPTX
Hackers, hackathons, and you
RTigger
 
PPTX
AJAX, JSON, and Client-Side Templates
RTigger
 
PPTX
JavaScript!
RTigger
 
PPTX
Parallel Processing
RTigger
 
PPTX
Node.js
RTigger
 
PPTX
Reactive Extensions
RTigger
 
PPTX
Sql vs NoSQL
RTigger
 
PPTX
Git’in Jiggy With Git
RTigger
 
PPTX
What The F#
RTigger
 
PPTX
Web Services
RTigger
 
PPTX
Total Engagement
RTigger
 
Give your web apps some backbone
RTigger
 
Hackers, hackathons, and you
RTigger
 
AJAX, JSON, and Client-Side Templates
RTigger
 
JavaScript!
RTigger
 
Parallel Processing
RTigger
 
Node.js
RTigger
 
Reactive Extensions
RTigger
 
Sql vs NoSQL
RTigger
 
Git’in Jiggy With Git
RTigger
 
What The F#
RTigger
 
Web Services
RTigger
 
Total Engagement
RTigger
 

Recently uploaded (20)

PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
July Patch Tuesday
Ivanti
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
July Patch Tuesday
Ivanti
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 

Caching up is hard to do: Improving your Web Services' Performance

  • 1. Caching Up is Hard To Do Chad McCallum ASP.NET MVP iQmetrix Software www.rtigger.com - @ChadEmm Improving the performance of your web services
  • 2. Here’s your API Client makes a request Bounces around the internet to web server Web server runs application, queries DB Database returns data from query Application serializes response and writes to client Bounces back through internet to client Client receives data Client The Internet Web Server Database
  • 3. An example request Client The Internet Web Server Database Client makes a request Bounces around the internet to web server Web server runs application, queries DB Database returns data from query Application serializes response and writes to client Bounces back through internet to client Client receives data 270ms 598ms3474ms 4342ms 528kb
  • 4. Start at the data • Optimize the database server • Logical Design – efficient queries, application-specific schema, constraints, normalization • Physical Design – indexes, table & system settings, partitions, denormalization • Hardware – SSDs, RAM, CPU, Network
  • 5. Between your App and the Data • Reduce the complexity of your calls – get only the data you need • Reduce the number of calls – return all the required data in one query • Make calls async – perform multiple queries at the same time* • The fastest query is the one you never make • Cache the result of common queries in an application-level or shared cache 598ms 315ms 47% Application Time
  • 6. Caching Data • Great for static or relatively unchanged data • Product Catalogs • Order History • Not so great for volatile data • Store Quantity • Messages • Comes with a memory price • Shared Cache when working with a web farm
  • 7. Inside your App • Standard “MVC” Flow • Request comes into Web Server over network connection • Framework parses request URL and other variables to determine which controller and method to execute, checking against routes • Framework creates instance of controller class and passes copy of request object to appropriate method • Method executes, returning an object to be sent in response • Framework serializes response object into preferred type as requested by client • Web server writes response back to client over network connection
  • 8. Inside your App • The most we can reasonably do is optimize our controller’s method • “Reasonably” meaning not doing crazy things to the underlying framework code / dependencies • The fastest method is one you don’t execute • Cache the serialized result of common API calls 598ms 296ms 51% Application Time
  • 9. Caching Responses • Great for endpoints that don’t take parameters • Get • Not so great for endpoints that do take parameters • Get By ID • reports with date ranges • Get with filters • Cache all supported serialization formats • Same cache concerns – memory usage, shared cache in farm setup
  • 10. From Server to Client • We can’t really change the topology of a client’s network connection • We can send less data • HTTP Compression 3474ms 1083ms 69% 528kb 129kb 76% Response Size Response Time
  • 11. HTTP Compression • Trading response size for server CPU cycles • Output can be cached (and often is) by web server to avoid re- compressing the same thing • Client requests compression using Accept-Encoding header 598ms 624ms 4% Application Time
  • 12. Paging • Don’t send everything! • Only returning 20 items • Page objects using OData Queries in WebAPI • Returning IEnumerable<T> will page in-memory • Returning IQueryable<T> will (attempt to) page at the database layer 3474ms 7ms 99.8% 528kb 10kb 98.1% Response Size Response Time
  • 13. Conditional Headers • Server can send either an ETag and/or Last-Modified header with response • ETag = identifier for a specific version of a resource • Last-Modified = the last time this resource was modified • Clients can include that data in subsequent requests • If-None-Match: “etag value” • If-Modified-Since: (http date) • Server can respond with a simple “304 Not Modified” response
  • 14. Conditional Headers 3474ms <1 ms 99.9% 528kb 0.3kb 99.9% • Avoid database calls to validate requests • Cache last modified times & etag values • May have to modify client code to retain and send Last-Modified and ETag values • Most browsers will automatically include If-Modified-Since, but some do not include If-None-Match • Non-browser code (SDKs, WebClient, HttpClient) Response Size Response Time 598ms 323ms 54% Application Time
  • 15. Client-Side Caching • Most browsers have a local cache – tell your clients to use it! • Expires header tells client how long it can reuse a response • Expires: Thu, 03 Apr 2014 03:19:37 GMT • Cache-Control: max-age=## (where ## is seconds) header does the same, but applies to more than just the client cache… • In either case it’s up to the client whether it uses the cache or not • Most browsers cache aggressively
  • 16. Intermediate Caching • Cache-Control header specifies who can cache, what they can cache, and how things can be cached • Public / Private – whether a response can be reused for all requests, or is specific to a certain user • max-age – the longest a response can be cached in seconds (overrides Expires header) • must-revalidate – if the response expires, must revalidate it with the server before using it again • no-cache – must check with the server first before returning a cached response
  • 17. Client-Side Caching • Great for static or relatively static data • Static HTML, JS, CSS files, or read-only lists of data that rarely change • Not so great for dynamic or mission-critical data • Hard to force clients to get latest version of data when they don’t even talk to the server • If you have to update before Expires or Max-Age runs out, you’ve got a problem 4342ms 100ms 97.7% Response Time
  • 18. Review • Optimize your database for your application • Cache on the server • Common database calls • Serialized results • Send less data • HTTP Compression • Paging • Conditional Headers / 304 Not Modified • Cache on the client • Expires and Cache-Control headers

Editor's Notes

  • #4: - Before animations, show “standard” endpoint code- Note on “bounces around to web server” – that’s about 8 hops from my home network to our azure instance in East Asia
  • #5: Mention the cool new in memory OLTP / tables and compiled stored procedures in SQL Server 2014
  • #6: You can return multiple result sets in one query – it takes some manual tweaking of the EDMX file and/or extra code in Entity Framework, but it is possibleKeep in mind high traffic + async can result in database overloadAfter last point, show call to cached-db endpoint
  • #7: Shared cache like memcached or a faster? database call (i.e. nosql, in memory table, etc)
  • #11: Show applicationhost.config transform, make request with Accept-Encoding: gzip header