This work introduces a simultaneous synthesis of membrane distillation systems with heat exchanger networks (HENs) for desalinating shale gas flowback and produce water. The direct contact and vacuum membrane configurations are the best options for desalination. Moreover, multistage membrane distillation systems usually have higher efficiencies than single-stages processes. For this reason, two different mathematical models for synthetizing multistage direct contact membrane distillation (MSDCMD) and multistage vacuum membrane distillation (MSVMD) are developed and optimized to achieve zero liquid discharge (ZLD) conditions. To this aim, brine discharges are considered to be near to the salt saturation conditions. The multi-stage superstructures are implemented in GAMS and optimized by SBB solver. The mathematical model is formulated via generalized disjunctive programming (GDP) and mixed-integer nonlinear programming (MINLP), to minimize the total annualized cost.This project has received funding from the European Union’s Horizon 2020 Research and Innovation Programme under grant agreement No. 640979