Overview
A Bangla online news portal with more than a million monthly readers was slowing down under load. Traffic on a news site is spiky: a breaking story can multiply requests within minutes, and every one of them lands on the same few pages. My job was to make those pages fast and keep the database out of the hot path.
Namespaced Redis caching
Hot articles, the home page and category listings are served from Redis. During a spike, most requests are answered from cache and the database sees only a fraction of the traffic.
Cache keys are namespaced by section. Publishing or updating a story clears only the keys it affects, so a whole section can be refreshed at once without flushing the rest of the cache and without readers seeing stale news.
PHP OPcache
OPcache is enabled and tuned so compiled PHP is reused across requests instead of being parsed again each time, which cuts CPU time on every page view.
Query fixes and indexing
- N+1 queries removed with eager loading on article, author and category listings, so a page makes a handful of queries instead of hundreds.
- Database indexes added on the columns behind the heaviest listing and search queries.
Tech stack
- Backend: Laravel, PHP, MySQL
- Caching: Redis (namespaced keys), PHP OPcache