Productionizing a Sliding-Window String Algorithm
Context: You have implemented a correct sliding-window algorithm for a classic string task (e.g., longest substring without repeating characters). You now need to evolve it into production-ready code used both as a library function and as a service.
Requirements:
-
Define a clear API boundary for both a library function and a service endpoint. Specify inputs/outputs, error handling, and how "character" is defined (bytes, code points, or grapheme clusters).
-
Validate inputs and character encodings. Specify accepted encodings, normalization behavior, and how invalid sequences are handled.
-
Handle very long inputs and memory limits. Describe streaming/iterative approaches, memory caps, and failure/degradation modes.
-
Ensure thread safety in a shared service. Address shared state, object pooling, and per-request isolation.
-
Add logging and metrics (latency, error rates, input sizes). Include tracing and sampling.
-
Design tests: unit, property-based, fuzz, concurrency, performance/soak, and regression tests.
-
Document complexity guarantees and practical performance characteristics.
-
Consider internationalization (Unicode) and define the unit of iteration; address normalization and grapheme segmentation.
-
Address security and resource-exhaustion risks (input limits, timeouts, decompression bombs, PII in logs).
-
Outline deployment, rollback, monitoring, and alerting plans with SLOs.