Using etcd as primary store/database?

后端 未结 3 1524
轻奢々
轻奢々 2020-12-28 12:12

Can etcd be used as reliable database replacement? Since it is distributed and stores key/value pairs in a persistent way, it would be a great alternative nosql database. In

3条回答
  •  萌比男神i
    2020-12-28 13:00

    First, no. Etcd is not the next nosql replacement. But there are some sort of scenarios, where it can come in handy.

    Let's imagine you have (configuration) data, that is mostly static but may change on runtime. Maybe your frontend needs to know the backend endpoints based on the customers country to comply with legal and you know the world wide rollout is done in phases.

    So you could just use a k8s configMap to store the array of data (country -> endpoint) and let your backend watch this configMap for changes. On change, the application just reads in the list and provides a repository to allow access to the data from your service layer. All operations need to be implemented in the repository (search, get, update, ...) but your data will be in memory (probably a linked hash map). So it will be very quick to retrieve (like a local cache).

    If data get changed by the application just serialize the list and patch the configMap. Any other application watching the configMap will update their internal state. However there is no locking. So quick changes may result in race conditions.

    etcd allows for 1Mb to be stored. That's enough for almost static data.

    Another application might be feature toggles. They do not changed that much but when they do, every application needs to know quickly and polling sucks.

提交回复
热议问题