Designing Login, Favorites, and Reading Experience for a Technical Column Platform
This article outlines a practical design approach for login state, first-time user guidance, and favorites on a content platform. It covers state machines for deferred actions, credential handling, idempotent write APIs, favorite data modeling, count consistency, permissions, performance, observability, and release checks.
Login, favorites, and first-time guidance are core features on most content platforms. When a user opens an article page, the system may face three kinds of state at once: anonymous visits, first-time use, and logged-in reading. The Login, First-time use, and Favorite entry points look simple, but they involve login state management, anonymous reading policies, action recovery, data consistency, permission checks, and performance. Poor design often causes problems such as a favorite button that flickers, a lost action after login redirect, duplicate favorites, unfavoriting that does not take effect, first-time guidance that interrupts reading, and counts that do not match the actual list. This article describes a practical design from a general technical perspective.
1. Build a State Machine Instead of Stacking Entry Points
Favoriting and login should not be handled as isolated buttons. Model them as a user action state machine with at least these states:
- Not logged in and not favorited: show the favorite entry, but clicking it starts the login flow.
- Not logged in, with a pending action stored locally: after login, resume the favorite action.
- Logged in and not favorited: show the favoritable state.
- Logged in and favorited: show the favorited state and support unfavoriting.
- First-time use: show a lightweight guide that does not block reading the article body.
- Expired login: after a silent refresh fails, switch to the logged-out state and keep the current page context.
Treat login as a precondition for the action, not for the page. Reading should work anonymously wherever possible. Write actions such as favoriting, commenting, and following should require login. This lowers the barrier on first load and keeps shared links and search-indexed pages working.
The following pseudocode shows the state check:
function onFavoriteClick(articleId):if not auth.isLoggedIn():pendingAction.save({type: "favorite", targetId: articleId})auth.redirectToLogin({returnUrl: currentUrl})returnfavoriteService.toggle(articleId)
After login redirects back, the frontend should read the pending action and check that its target matches the current page. This prevents a favorite action from page A being applied to page B. Pending actions should have an expiration time and should only allow action types from an allowlist.
2. Login State: Short-Lived Credentials, Refreshable, and Degradable
Login state design should follow one principle: the server is trusted, and the client stays lightweight. When the client stores short-lived access credentials and refresh credentials, avoid placing sensitive information where any script can read it. The server must verify identity and permissions on every write. For write operations such as favoriting, also consider duplicate submissions, cross-site request forgery, and API abuse through high request volume.
Recommendations:
- Keep access credentials short-lived, and rotate refresh credentials.
- When login expires, try a silent refresh first. Redirect to login only if the refresh fails.
- Use idempotency keys or request fingerprints on write endpoints, so network retries do not cause duplicate writes.
- Apply reasonable rate limits to favorite and unfavorite requests.
- Validate post-login return URLs against an allowlist to prevent open redirects.
3. First-Time Guidance: Lightweight, Dismissible, and Measurable
“First-time use” does not mean “forced login.” The goal of first-time guidance is to help users understand favorites, reading progress, or account sync. It should not block content. Guidance can use a tooltip, a bottom bar, or a one-time card, and it should meet these requirements:
- Show only on the first visit or the first time the user triggers a related action.
- Allow users to dismiss it, and follow the policy so it does not reappear after dismissal.
- Track impressions and click events.
- Do not cover the core area of the article body.
- Configure separate copy and frequency settings for logged-in and logged-out users.
Store the guidance policy on the server so you can roll it out gradually and roll it back quickly. Local flags in the frontend can help, but the server or a configuration service should control final frequency.
4. Favorite Data Model: Unique Constraints and Soft Deletion
The core of favoriting is a user-target-status relationship. Use a relational table with at least these fields: user ID, target type, target ID, status, creation time, update time, and idempotency key. Add a unique constraint on user and target, so concurrent requests cannot create the same favorite twice.
Example SQL:
CREATE TABLE user_favorite (id BIGINT PRIMARY KEY,user_id BIGINT NOT NULL,target_type VARCHAR(32) NOT NULL,target_id BIGINT NOT NULL,status SMALLINT NOT NULL, -- 1 = favorited, 0 = unfavoritedidempotency_key VARCHAR(64),created_at TIMESTAMP NOT NULL,updated_at TIMESTAMP NOT NULL,UNIQUE (user_id, target_type, target_id));
Unfavoriting can use a status flag for soft deletion, which supports auditing and recovery. If the business only needs the current state, a physical delete also works, but it must remain idempotent. Paginated favorite lists should use stable ordering, such as update time in descending order with the unique key as a cursor. This prevents duplicate or missing items across pages.
Do not count favorites by scanning the full table on every request. Instead, write to the fact table, update the count asynchronously, and reconcile periodically. List queries should use the fact table as the source of truth. The count cache can be briefly eventually consistent, but it needs a reconciliation job and monitoring.
5. Idempotency and Concurrent Consistency
Both favoriting and unfavoriting should be idempotent. While a request is pending, the frontend should disable the button or merge repeated clicks. The server ensures consistent results through unique constraints, idempotency keys, or conditional status updates.
Pseudocode:
function toggleFavorite(userId, targetType, targetId, desiredStatus, idemKey):begin transactionrow = select ... for updatewhere user_id=? and target_type=? and target_id=?if row is null:insert (userId, targetType, targetId, desiredStatus, idemKey)else if row.status != desiredStatus:update status=desiredStatus, updated_at=now()commitasync publishFavoriteCountEvent(targetType, targetId, desiredStatus)
For concurrent favorite and unfavorite requests, the final state should follow the last valid request, or a version number defined by the business logic. Do not rely only on the frontend button state to determine the server result. After a successful write, refresh the UI with the state returned by the server.
6. Permissions, Security, and Privacy
Check object visibility before a user favorites anything. Users can only favorite objects they have permission to access. Unfavoriting should also verify ownership, so a user cannot change another user’s favorites by guessing object IDs. For private, delisted, or deleted content, show a placeholder or filter the item out of the favorites list. This prevents leaking sensitive information.
Add rate limiting, anomaly detection, and audit logs. The favorite endpoint handles low-frequency writes, but scripts may still abuse it. Apply rate limits per user, device, and endpoint. Logs should not contain full credentials or sensitive article content. Record only the necessary request identifiers, result codes, and latency.
7. Performance and Experience Optimization
Prioritize the reading experience on first load. Batch favorite status queries instead of sending one request per card. Do not send favorite status queries for logged-out users. Render the favorite button in a neutral state first, then update it when the status returns. This reduces layout shifts. List pages can use skeleton screens and local caching to improve perceived performance.
For hot object counts, a cache service can handle read traffic. If the cache misses or fails, degrade gracefully by returning the result from the fact table or hiding the count. Do not block the article body. Update the cache asynchronously through events, and set expiration times and reconciliation jobs.
8. Observability and Release Checks
Monitor these metrics: favorite endpoint success rate, P99 latency, duplicate submission rate, idempotency conflict count, post-login redirect success rate, pending action recovery rate, count reconciliation deviation, and first-time guidance dismissal rate. Alerts should separate client-side errors from server-side errors.
Before release, check at least:
- Clicking favorite while logged out opens the login page and returns to the correct page.
- After login, the pending action runs only once.
- Repeated clicks and network retries are idempotent.
- After unfavoriting, the list and count become consistent.
- First-time guidance can be dismissed and does not cover the article body.
- Users without permission cannot favorite restricted objects.
- The article remains readable when the cache is unavailable.
9. Summary
Login, first-time guidance, and favorites are core features on most content platforms. Good design depends less on adding more entry points and more on combining user state, action recovery, data consistency, and permissions in one state machine. Prioritizing anonymous reading, requiring login only for writes, using idempotent APIs, unique constraints, asynchronous counting, and thorough observability helps build a stable and maintainable favorites system without hurting the reading experience.
