The current Redis implementation provides a solid foundation for session management and transient state. However, it faces critical risks in high-load scenarios and production environments due to single-instance infrastructure, lack of transit security, and rudimentary connection handling.
tier = "BASIC" in Terraform.google_redis_instance resource.auth_enabled is not set in Terraform.RedisClient uses redis.from_url without explicit connection pool tuning or retry strategies.TeslaFleetService correctly uses Fernet (AES-256) to encrypt tokens before saving to Redis.settings.TOKEN_ENCRYPTION_KEY. If this key is not rotated, a historic dump of Redis could eventually be decrypted if the key is ever leaked.volatile-lru (default) which is safe, but memory pressure could lead to premature session eviction.Spec: Upgrade to Standard HA and Enable Security
1. Upgrade Tier: Change tier from BASIC to STANDARD_HA.
2. Enable Auth: Set auth_enabled = true and retrieve the auth_string via a data source or output to store in Secret Manager.
3. Enable TLS: Set transit_encryption_mode = "SERVER_AUTHENTICATION".
app/core/redis.pySpec: Robust Connection Management 1. Tuned Connection Pool:
self._client = redis.from_url(
settings.REDIS_URL,
decode_responses=True,
max_connections=20, # Adjust based on Cloud Run concurrency
socket_timeout=5.0,
socket_keepalive=True,
retry_on_timeout=True
)
REDIS_URL to rediss:// (note the double 's') and configure SSL context to trust GCP's CA.Spec: Envelope Encryption
1. Move from a static TOKEN_ENCRYPTION_KEY to GCP KMS (Key Management Service).
2. Use the Service Account identity to "Wrap/Unwrap" session keys, ensuring the actual master key never leaves GCP's Hardware Security Modules (HSM).
Spec: Redis Health Dashboard
1. Add alerting for redis.googleapis.com/stats/memory/usage_ratio > 0.8.
2. Monitor redis.googleapis.com/network/instanteous_ops_per_sec to detect thundering herd issues during surges.