1

I'm facing a very simple scenario that should have a simple solution, but can't seem to figure it out.

I'm trying to design a RESTful app that replaces a (stateful) remote for an electrical appliance. The frontend of the app simply shows the current state of the appliance and sends a new state to the backend if the user wishes to change it.

The backend server simply accepts either a GET request to which it responds with the state that was last set or a POST request that sets the state by issuing a command to the appliance (over a serial port).

What puzzles me is how to save the state of the appliance here. Server private memory is out of the question since multiple server processes can be spawned, a disk access for every key-press seems inefficient, and the state message has to pass through to the appliance before the state is advanced on the server.

Anything I think of is either platform-specific (e.g. involving POSIX message queues) or overly complex, but I just feel like this is a common enough problem that it has to have an associated design pattern. That's why I decided to come here and ask for advice before starting to over-complicate things

Fran Borcic
  • 119
  • 2
  • Choosing a storage medium isn't choosing a design pattern. Design patterns only become relevant here when you've made a decision on how/where to store it. I'm also unsure why exactly you're discounting private storage as the issues of multiple processes can be worked around (individual storage per process, proper file locking logic to ensure multiple processes can share the storage, ...) – Flater Dec 23 '19 at 02:10
  • 1
    It's hard to tell where you see the problem. Are you concerned that the server gets out of sync with the device? Are you concerned that users may use the device's 'control panel' independently of the server? Are you concerned that two users of the server may try to simultaneously change device configuration in conflicting ways? – joshp Dec 23 '19 at 07:38
  • What I do when I hit a roadblock like this is start defining an approach to the level of detail where I can implement it. Then review what's wrong with the approach and consider whether there are useful modifications or a better approach. It sounds from this question that you are just generally unsure and not clear on what obstacles you might actually meet. If you know what problems, maybe spell them out here to make it easier to answer. – joshp Dec 23 '19 at 07:42

0 Answers0