REDDIT 原始帖子

Building a responsive webmail frontend: Should I cache message bodies or always fetch them live?

Looking for advice on building a responsive webmail frontend (Kerio Connect + SOGo) I'm building an internal webmail application for our company and would love to hear from anyone who has worked with Kerio Connect, SOGo, Dovecot, Exchange, Zimbra, or similar…

原帖正文r/selfhosted

Looking for advice on building a responsive webmail frontend (Kerio Connect + SOGo) I'm building an internal webmail application for our company and would love to hear from anyone who has worked with Kerio Connect, SOGo, Dovecot, Exchange, Zimbra, or similar mail systems. Current Architecture Backend: Next.js (Node.js) Mail Server: Kerio Connect Webmail: SOGo Message list is synchronized and cached in PostgreSQL. Message bodies are fetched live from SOGo. SOGo sessions are persisted and reused successfully, so I'm not logging in on every request. Current flow: Frontend ↓ Next.js API ↓ Reuse persisted SOGo session ↓ Fetch HTML body from SOGo ↓ Return HTML to frontend Current Issues 1. Opening an email is noticeably slower than loading the message list The message list loads almost instantly because it comes from PostgreSQL. However, every time a user opens an email, the application must: Send a request to SOGo Retrieve the HTML body Return it to the frontend Render the HTML Even reopening the same email a few minutes later triggers another request to SOGo. 2. No message body caching I intentionally chose not to cache message bodies because I wanted every email to be fetched directly from the mail server. As a result: Reopening the same email always makes another request. Switching to another email and back makes another request. Opening an email from days ago also makes another request. I'm starting to question whether this is the right architectural decision. 3. Large HTML emails are significantly slower Simple emails load quickly. However, emails containing: Outlook signatures Inline images Large HTML tables Complex HTML layouts take noticeably longer to open. I'm trying to determine where the bottleneck actually is: SOGo generating the HTML? Network latency? Backend processing/sanitizing HTML? Browser rendering? 4. Some redundant database lookups During a single body request, my application performs multiple database lookups for credentials and session information. These can probably be optimized or memoized, although I don't believe they're the primary performance issue. Questions Do webmail clients like Gmail, Outlook Web, Roundcube, or Thunderbird cache message bodies after the first time they're opened? If you were building a webmail client on top of Kerio/SOGo/IMAP, would you: Always fetch the body live? Cache message bodies? Use a hybrid approach? For large HTML emails, where is the bottleneck usually found? Mail server Network Backend HTML processing Browser rendering Are there any well-known architectural patterns for building a responsive webmail frontend on top of an existing mail server? Constraints I don't want to modify Kerio Connect. I'd prefer not to permanently store message bodies unless necessary. SOGo sessions are already persisted and reused. My goal is to make opening emails feel as responsive as Gmail or Outlook while keeping the architecture relatively simple. I'm mainly looking for architecture and design advice rather than framework-specific solutions. If you've built or optimized a production webmail client before, I'd really appreciate hearing how you approached message body retrieval and caching.

已收录讨论

8 条评论

u/asimovs-auditor

Expand the replies to this comment to learn how AI was used in this post/project.

u/Old_Succotash3238OP

Thanks! That makes sense. One thing I'm still wondering is how production webmail clients usually invalidate the cached body. Since the message body is effectively immutable after delivery, do clients typically keep it indefinitely until the message is deleted, or do they still use a TTL or revalidation strategy?

u/Kautiontape

That's a function of how much storage you have. You'll be clearing them out as your cache storage gets full. I haven't built a production webmail app specifically, but it's a common enough problem, but I'm sure if you hop around and look at source code for them like RoundCube it'll just be LRU once the cache hits a limit because there's really no reason to do otherwise. It's text so you can store a lot, and redownload is quick if you have a bunch of users flying through tons of mail faster than other users revisit old mail. If you do have the latter, then just use a frequency based cache removal policy and you're fine. Don't reinvent any wheels, don't worry about TTL, don't worry about revalidation in most circumstances. I'm sure there are edge cases, but not on the immutable mail content.

u/PaperDoom

Yes! We need every new email developer to start pushing JMAP. The new Bulwark webmail that was made by the Stalwart mail people is pretty great, JMAP first.

u/GolemancerVekk

Yes, every email client caches messages as much as possible. Messages aren't changing once you've received them so you can cache everything about them.

u/TCB13sQuotes

Except for Roundcube that can be configured to cache or not to cache the body.

u/mjdau

Please consider using JMAP, RFC 8620/8621. There are several client and server implementations you can look at and interact with.

u/PubicSkoolEducashun

I did not know that you could delete the comment from the automod about how AI was used.