feat: Agnostic Persistence Layer, MongoDB Support & Rich API Timestamps#284
Closed
L7NEG wants to merge 1 commit intoPhineas:mainfrom
Closed
feat: Agnostic Persistence Layer, MongoDB Support & Rich API Timestamps#284L7NEG wants to merge 1 commit intoPhineas:mainfrom
L7NEG wants to merge 1 commit intoPhineas:mainfrom
Conversation
Introduce MongoDB-backed persistence and migration tooling and wire it into the system. Adds Lanyard.Connectivity.MongoDB and a Persistence adapter, plus a Migration module to move API keys, KV, last_seen and metrics from Redis to MongoDB. KV and API key flows are updated to use the new Persistence/MongoDB APIs (bot commands, KV interface, API routes). Redis is made optional (graceful no-redis handling) and a Persistence fallback is used for metrics, last_seen and monitoring_since; metrics are now collected with initial values and periodically flushed from a GenServer. Dockerfile and README updated to include MongoDB in deployment examples and demonstrate durable mode; various small UX/link/message formatting and gateway/presence improvements to load persisted KV, last_seen and monitoring_since on init.
Repository owner
locked and limited conversation to collaborators
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lanyard Persistence & Deployment Upgrade
I have implemented a comprehensive overhaul of Lanyard's persistence layer, transforming it into a database-agnostic, production-ready system with advanced API features and infinite historical durability.
Key Features & Architectural Changes
Lanyard.Connectivity.Persistence) that handles data storage across MongoDB and Redis with intelligent fallback logic.Lanyard.Metrics.PrometheusGenServer that periodically flushes bot metrics (users monitored, socket sessions, etc.) to your database every 60 seconds.last_seenandmonitoring_sinceare now rich objects containing both Unix and Raw ISO8601 strings.last_seen_readableandmonitoring_since_readablefields for instant debugging.monitoring,users, andkv) to ensure 2022 records are never lost.prometheus_ex.Real-Time Sync & Persistence Specs
When deploying Lanyard, it's important to understand how different backends handle real-time cross-node synchronization versus long-term data durability.
Why MongoDB isn't "Real-Time" for Sync
While MongoDB is the gold standard for durability, it isn't designed for the ultra-low-latency real-time Publish/Subscribe (Pub/Sub) required to sync presence data between worldwide bot nodes instantly. MongoDB's Change Streams are powerful but are significantly heavier than Redis's native Pub/Sub engine.
What happens if I only use MongoDB?
kv,last_seen, andmetricswill be persisted forever. (note: some in metrics won't as these are real-time/counters for real users ex: lanyard_connected_sessions and lanyard_monitored_users and status in {user-id} in users route)Database Optionality & Fallback Logic
Lanyard can now run in three different persistence modes:
MONGODB_URIis set, your data is stored permanently.REDIS_URIis set, you get high-speed cross-node presence sync.API Breakdown (JSON Example)
live demo: https://rpcapi.ftp.sh/v1/users/669453086418534400
{ "data": { "kv": { "6": "7", "Location": "Earth" }, "discord_user": { "avatar": "ebb7be6e257599994a3e29105996ad08", "avatar_decoration_data": { "asset": "a_c48b135704ecb5c88f2f71f6c8bcce2f", "expires_at": null, "sku_id": "1357589632581374042" }, "bot": false, "collectibles": { "nameplate": { "asset": "nameplates/gothica/nevermore/", "expires_at": null, "label": "COLLECTIBLES_GOTHICA_NEVERMORE_NP_A11Y", "palette": "white", "sku_id": "1462116614131548265" } }, "discriminator": "0", "display_name": "L7NEG", "display_name_styles": null, "global_name": "L7NEG", "id": "669453086418534400", "primary_guild": { "badge": null, "identity_enabled": false, "identity_guild_id": null, "tag": null }, "public_flags": 64, "username": "l7neg" }, "monitoring_since": { "raw": "2022-10-01T16:22:06Z", "unix": 1664641326 }, "activities": [], "last_seen": { "raw": "2026-04-03T03:07:30.417Z", "unix": 1775185650417 }, "discord_status": "offline", "active_on_discord_web": false, "active_on_discord_desktop": false, "active_on_discord_mobile": false, "active_on_discord_embedded": false, "active_on_discord_vr": false, "listening_to_spotify": false, "spotify": null, "last_seen_readable": "April 03, 2026 03:07:30 AM", "monitoring_since_readable": "October 01, 2022 04:22:06 PM" }, "success": true }This upgrade ensures Lanyard remains the state-of-the-art presence engine for the community.
Author: L7NEG (via Antigravity)
References: Improved from PR #264 and PR #265.