Sometimes a user's avatar briefly shows someone else's, and re-uploading fixes it—does adding a random string to the filename help?
An avatar mix-up is usually not the database attaching an image to the wrong person. More often, two accounts' avatars end up pointing to the same URL: the upload filename or path is not unique, a later upload overwrites the earlier image, and CDN and browser caching by URL compound the issue, so A opens their own page and sees B's image. The first step is not to dig through code. Copy the image addresses from both accounts and compare them character by character: if the addresses are exactly the same, the problem is in naming and the storage layer; only if they differ do query conditions, field length, and cache keys come into play.
To users, an avatar mix-up looks like a security problem; in engineering, it is often just an overwrite
It usually takes three forms, each pointing to a different layer: when two people see each other's images, the storage key is most likely colliding; when the same account alternates between old and new images across refreshes, CDN or multi-level cache is most likely out of sync; when the list shows the new image but the detail page still shows the old one, the two ends are most likely using different cache keys or image retrieval APIs. Identifying the form first can cut troubleshooting time in half.
It deserves priority because an avatar is a direct sign of account identity, and a mix-up makes customers' first reaction 'my account has been logged into by someone else.' Trust issues like this usually rank higher than feature defects. In 2026 projects, avatars, attachments, and contract scans often share the same upload channel, so one lax naming rule can spread the impact from avatars to all upload-related business.
Where filenames are most likely to collide
Many teams assume that using a timestamp makes a filename unique, but problems most often arise in concurrency, precision, and whether the original filename is kept. There is only one standard for whether naming is acceptable: any two uploads must generate different storage keys. A second-level timestamp that is only 'probably different' does not qualify.
- Original filename plus a second-level timestamp: two users save the same image from WeChat and upload it in the same second, producing exactly the same path.
- User ID used directly as the filename: after changing to user_1001.jpg, changing the avatar overwrites the same-named object, the URL does not change, and the cache still returns the old image.
- Direct frontend upload with the key generated by the client: an inaccurate client clock or reuse of the same template code can produce duplicate results.
- Overwrite on the same key plus CDN: the origin has already overwritten the object, but edge nodes still return the old object according to the old cache time.
Of these four, the first two can be spotted in code review; the last two can only be inferred backward from production symptoms.
Troubleshooting order: align the addresses first, then narrow down layer by layer
It is best to fix the troubleshooting order into a checklist so you do not rely on guesses each time. Use the URL as the single clue to split the problem into the storage side and the query side; if the order is reversed, it is easy to refresh the cache and restart once, only to find the problem unchanged.
- Export the raw avatar URLs from both records: keep the protocol, domain, path, and query string; the bar is being able to answer clearly whether they are the same address.
- If the URLs are the same, check the storage object: see whether the last modified time of that key is later than A's upload and earlier than B's upload; that basically confirms an overwrite.
- If the URLs differ, check writes and queries: whether the field length truncates the value, whether the ORM has second-level cache enabled, and whether the query is missing the account dimension.
- Then check the cache keys of CDN and reverse proxy: whether the query string is ignored, whether cache time is too long, and whether the refresh only hit the origin.
- Finally check the browser side: whether the img src is being served by a Service Worker or local cache, and whether the issue reproduces on another device or network.
The last modified time in step 2 carries the most information: it does not depend on logs and does not require reproduction, yet it can pin down the conclusion. If a timestamp can settle the question, there is no need to trade two hours of full-stack troubleshooting for it.
How to choose among three naming approaches, and what experience range the rework usually falls into
No single naming approach fits every business. Based on common delivery practice in 2026, weigh three dimensions: whether content deduplication is needed, whether long-term caching is needed, and whether cleanup and migration by account are needed.
- Random name (UUID or Snowflake ID plus extension): simple to implement and concurrency-safe, suitable for low-duplication cases such as avatars and ID documents; the cost is that the same image may be stored multiple times, slightly raising storage cost.
- Content hash: naturally deduplicated, cache-friendly, and able to verify integrity; however, private files with the same content get the same address, so namespaces require extra handling.
- Directory isolation (random names under directories split by account or date): makes account-based cleanup, migration, and permission policies easier; the cost is longer paths, and CDN origin-pull rules must be updated accordingly.
Estimate rework effort using an experience range: converging naming in the upload API and backfilling historical data typically falls in the 1 to 3 person-day range; if the bucket has versioning enabled and historical files can be batch renamed, take the lower end; if multiple clients must change at the same time and cache refresh windows must be coordinated, it often moves above 3 person-days. The main cost is not writing code, but handling historical files and coordinating cache refresh windows.
Content hashing for private files requires salting or an independent namespace; otherwise, whether a file exists becomes inferable information. This is especially important for contract scans and identity proof materials, and it is a compliance issue, not a technical preference.
When to change it, and when to leave it alone
Cases suitable for naming convergence first: resources are uploaded by users, multiple accounts coexist, object storage or CDN is already in use, and there has been historical alternation between old and new images. For these systems, rework cost is controllable and the benefit directly lands on trust.
It is also worth stating clearly what does not need major changes: a pure intranet single-machine system where files are accessed by only one account and there is no CDN only needs unique naming, without introducing hashing and versioning systems; for temporary files such as export intermediates, daily cleanup is more cost-effective than precise naming; if all historical resources have been moved to private signed access and every access URL is different, the impact of overwrites is limited and priority can be lowered.
Unique naming is necessary but not sufficient: if the URL is unique but the cache key carries no version, avatar mix-ups can still occur. Therefore, acceptance criteria must include both 'two uploads produce different keys' and 'after changing the image, the new address takes effect on the cache side.'
Delivery reality: skipping one line of random suffix later costs multiples of the time to fix
One project had tight budget and schedule constraints; the assets were uploaded by the client's operations staff, and the system also had to support an old Android WebView. The team initially named files using 'user ID plus a second-level timestamp.' Load testing did not expose the issue, but within two weeks of launch there were two avatar mix-ups, and the client directly classified them as account security incidents. The follow-up was not just adding a random suffix: it also included renaming historical files, a full CDN refresh, and a round of guidance for users to re-upload. Actual effort fell in the typical range of 3 to 7 person-days, clearly larger than the half-day change at the beginning. Rework like this almost always happens after someone has already seen the wrong image, so the earlier the naming is tightened, the lower the cost.
FAQ
When avatars are mixed up, should I refresh the CDN first or check the database first?
Compare the image URLs of the two accounts first. If the URLs are the same, check the storage object and cache key; only if they differ should database fields and query conditions be checked. Reversing the order is the same as refreshing the cache for nothing.
If a file has already been overwritten, can the original image still be recovered?
It depends on whether object storage versioning is enabled. If it is, the image can be retrieved from a historical version; if not, an overwrite is unrecoverable and the only option is to ask the user to re-upload. So first confirm the bucket's versioning status.
If I add a random filename, will avatar mix-ups stop?
A random name can solve overwrites, but not caching. If the CDN cache key ignores the query string, or cache time is set too long, edge nodes may still return the old object after the image is changed.
Is there a leak risk if private files are named with content hashes?
There is an inference risk: the same file has the same hash, and anyone who knows the hash can determine whether the file exists. For private scenarios, use salting or random names, and keep server-side permission checks.
If the system already uses object storage or CDN and has shown alternation between old and new images, run an address spot check first: randomly sample several accounts, export their image URLs, and see whether any are duplicated; this usually takes less than half a day. Conversely, a small intranet single-machine system with no cache layer does not need special rework for this; keeping existing naming unique is enough.
-
Ops says Redis memory is only at 60%, but a batch of users was kicked back to the login page this morning—is adding memory now still in time?
Date: Nov 29, 2026 Read: 5
-
Query API works in the page but downloads when pasted into the browser address bar—should I check the gateway first or the response headers?
Date: Nov 28, 2026 Read: 7
-
After switching the site to HTTPS, images in old articles are blank on the client side but load fine for us—does that mean we don’t need to touch the image library?
Date: Nov 26, 2026 Read: 21
-
Customers say they never receive the SMS code while our backend shows every send as successful—at acceptance, should the issue count against the channel or against us?
Date: Nov 25, 2026 Read: 27
-
Client double-clicks an exported list in Excel and Chinese becomes question marks, but Notepad shows it normally—is the file corrupted or is it the wrong way to open it?
Date: Nov 24, 2026 Read: 31




