1. Taking media bytes off the application server
Students share images, study documents, and voice notes all day, often over patchy hostel Wi-Fi or congested cellular data. Streaming multi-megabyte uploads through Spring Boot workers ties up request threads and bloats server memory.
In MediaServiceImpl, the backend validates attachment counts (maximum 10 files, 100 MB total payload) and per-type byte limits (25 MB images/docs, 50 MB video), then signs short-lived PUT URLs via AWS SDK S3Presigner pointing straight at Cloudflare R2.
On the Expo React Native client, uploads are bounded to 3 concurrent transfers with retry backoff (1.5s per attempt) and explicit cancel guards so stale retries cannot overwrite UI state after a user cancels.
2. L1 Caffeine + L2 Redis with stampede locks
Repeated permission lookups across channels, community settings, and feeds can overwhelm PostgreSQL during peak campus hours between classes.
AbstractLayeredCacheService checks an in-process Caffeine L1 cache (5-minute TTL, capped at 10,000 keys) first, falls back to shared Redis L2 (30-minute TTL), and uses a ConcurrentHashMap of ReentrantLocks when stampede protection is enabled so bursts against an uncached key hit the database once instead of dozens of times.
3. Persisting STOMP principals across WebSocket frames
During real-time channel messaging, validating JWTs purely on initial handshake left individual SEND frames without a populated security context.
WebSocketAuthInterceptor extracts the Bearer token on StompCommand.CONNECT into WebSocket session attributes and rebuilds the authenticated Spring Security principal on subsequent SEND frames without forcing clients to repeat full HTTP handshakes.
4. Keeping claims honest
Around 1,000 students at Graphic Era Hill University use GEHU Connect, which is enough traffic to expose every rough timeout, retry edge case, and UI lag that local testing hides. Every architecture choice above came from fixing real friction rather than premature optimization.