A method of processing data messages at a first managed forwarding element, MFE, of a plurality of MFEs in a datacenter , wherein a plurality of logical networks are implemented in the datacenter , wherein the first MFE and a particular endpoint machine of a plurality of endpoint machines execute on a particular host computer , wherein the particular endpoint machine is a source of a data message and operates within a particular logical network of the plurality of logical networks, the method comprising: at the first MFE : receiving the data message from the particular endpoint machine , wherein the data message is destined for an external network , wherein the external network is a second datacenter; identifying the logical networks associated with the source and destination of the received data message; identifying that the data message requires gateway service processing before being sent to the external network ; identifying a particular MFE of the plurality of MFEs assigned to provide the gateway service processing for the identified logical network, wherein the plurality of MFEs : a) execute on a plurality of host computers along with the plurality of endpoint machines , b) operate within the plurality of logical networks, and c) are assigned to provide the gateway service processing for the different logical networks; and when the particular MFE is the first MFE , providing the gateway service processing for the data message and forwarding the data message to an edge router that provides access to the external network , wherein in response to determining that the particular MFE is a second MFE different from the first MFE , the first MFE forwards the data message to the second MFE for the second MFE to perform the gateway service processing and forward the data message to the edge router , wherein a set of logical networks in the plurality of logical networks are each assigned an MFE in the plurality of MFEs to provide gateway service processing for the logical network, wherein the set of logical networks comprises at least one logical network that requires stateful gateway service processing. receiving the data message from the particular endpoint machine , wherein the data message is destined for an external network , wherein the external network is a second datacenter; identifying the logical networks associated with the source and destination of the received data message; identifying that the data message requires gateway service processing before being sent to the external network ; identifying a particular MFE of the plurality of MFEs assigned to provide the gateway service processing for the identified logical network, wherein the plurality of MFEs : a) execute on a plurality of host computers along with the plurality of endpoint machines , b) operate within the plurality of logical networks, and c) are assigned to provide the gateway service processing for the different logical networks; and a) execute on a plurality of host computers along with the plurality of endpoint machines , b) operate within the plurality of logical networks, and c) are assigned to provide the gateway service processing for the different logical networks; and when the particular MFE is the first MFE , providing the gateway service processing for the data message and forwarding the data message to an edge router that provides access to the external network , wherein in response to determining that the particular MFE is a second MFE different from the first MFE , the first MFE forwards the data message to the second MFE for the second MFE to perform the gateway service processing and forward the data message to the edge router , wherein a set of logical networks in the plurality of logical networks are each assigned an MFE in the plurality of MFEs to provide gateway service processing for the logical network, wherein the set of logical networks comprises at least one logical network that requires stateful gateway service processing. <EOS>