Network function (NF) developers need to provide highly available solutions with diverse packet processing features at line rate. A significant challenge in developing such functions is to build flexible software that can be adapted to different operating environments, vendors, and operator use-cases. Today, refactoring NF software for specific scenarios can take months. Furthermore, network operators are increasingly adopting fast-paced development practices for continuous software delivery to gain market advantage, which imposes even shorter development cycles. A key aspect in NF design is state management, which can be optimized across deployments by carefully selecting the underlying data store. However, migrating to a data store that suits a different use-case is time consuming because it requires code refactoring while revisiting its application programming interfaces, APIs. In this paper we introduce FlexState, a state management system that decouples the NF packet processing logic from the data store that maintains its state. The objective is to reduce code refactoring significantly by incorporating an abstraction layer that exposes various data stores as configuration alternatives. Experiments show that FlexState achieves significant flexibility in optimizing the NF state management across several scenarios with negligible overhead.