Live data from Hacker News

Ask HN: What are modern architecture patterns for desktop applications?

news.ycombinator.com

1–10 of 25 posts

Ask HN: What are modern architecture patterns for desktop applications?

#1
I built a web based prototype for an application using a Docker microservices architecture: postgreSQL, redis, traefik, etc. - the regular stuff - which works great. Now, the application's usecase is actually better suited in a offline environment with a standalone executable, and I'm struggling to make this transition.

(How does the app work? Think of the application as a file indexing system: you specify a folder on your local hard drive and the program will analyze the files (might take up to 30 minutes) and store metadata for it in a search-optimized datastructure.)

From what I understand most applications also separate frontend and backend layers and let the processes communicate via message passing over some form of channel and protocol. The solutions I found include Unix Sockets with gRPC (https://docs.microsoft.com/en-us/aspnet/core/grpc/interprocess?view=aspnetcore-6.0), local HTTP Servers with a REST API or gRPC, even JSON over stdin/stdout (https://github.com/xi-editor/xi-editor). Solutions for datastorage include custom file formats, sqlite databases or bundled mongodb instances into the main application.

I figured out the backend part with analysis running multithreaded and writing into a sqlite database. For the IPC I spawn a gRPC Server which clients connect to over HTTP/2. That way I compile a platform agnostic backend and platform specific frontends. It all works okish but I feel like it's unnecessarily complicated and there could be a common strategy I am missing.

*TL;DR: What are modern architectures for desktop applications equivalent to a microservice architecture with backend/frontend separation, message queueing, pub/sub, authentication, ...?*

Re: Ask HN: What are modern architecture patterns for desktop applications?

#3
Sounds like you're bringing network tech in, which is unnecessary and costly.

I suggest you considers structuring the reusable pieces as a library and then reaping the benefits of strong typing and absurdly low latency when building the non reusable UI.

Akka might be interesting if you were a team but you really can just use regular old method calls.

Re: Ask HN: What are modern architecture patterns for desktop applications?

#5
OP, it seems like you are overdesigning. IPC takes way more effort than direct function calls - it's effort that is better spent on something actually useful. Let the requirements pick design patterns, don't try to cram in as many design patterns as possible.

Event handlers, model/view, independent-ish subsystems, frontend/backend are some typical patterns in desktop applications. Some of it depends on your framework - much of the architecture will be defined by the framework. The default should be doing things in the canonical way for the framework.

Re: Ask HN: What are modern architecture patterns for desktop applications?

#6
On Linux, you want to check D-Bus [1] if you need IPC (but that is primarily used for message exchange between different desktop apps). Everything else you mentioned sounds like a recipe for bloat. Desktop GUI libraries (like Qt or Gtk) ship everything you'll need and you can get a platform-agnostic app without much of a problem.

> running multithreaded and writing into a sqlite database.

sqlite doesn't support multithreaded writes, so you'll have to use a queue or something like that. Qt/Gtk ships with that as well.

[1] https://www.freedesktop.org/wiki/Software/dbus/

Re: Ask HN: What are modern architecture patterns for desktop applications?

#7

OP, it seems like you are overdesigning. IPC takes way more effort than direct function calls - it's effort that is better spent on something actually useful. Let the requirements pick design patterns, don't try to cram in as many design patterns as possible. Event handlers, model/view, independent-ish subsystems, frontend/backend are some typical patterns in desktop applications. Some of it depends on your framework…

I agree if you have technical requirements needing it to support (x transactions)/second coming in, optimize your ingress architecture. If these transactions/messages are based on UI interaction in a single offline application, I can't imagine this being too complicated to begin with.

Re: Ask HN: What are modern architecture patterns for desktop applications?

#8
What's your UI framework? This question is difficult to answer without knowing that.

In general it sounds like you're working too hard to introduce a strict process separation between the UI and the backend. A desktop application won't have multiple clients connecting to the backend, so you can run everything in one process. That's the use case for which SQLite is designed.

Your UI framework may introduce some level of process separation anyway: if the UI is a WebView or Electron, then it's going to run the renderer in its own process. So there's no need to go crazy with splitting up into tiny little services.

Post reply on HN