# How does \`serve\` create replica and allocate resources when doing composition?

**URL:** <https://discuss.ray.io/t/how-does-serve-create-replica-and-allocate-resources-when-doing-composition/22115>\
**Category:** Ray Serve\
**Created:** [March 24, 2025, 3:08am UTC](https://discuss.ray.io/t/how-does-serve-create-replica-and-allocate-resources-when-doing-composition/22115 "2025-03-24T03:08:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mk6](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@mk6](https://discuss.ray.io/u/mk6)\
**Post date:** [March 24, 2025, 3:08am UTC](https://discuss.ray.io/t/how-does-serve-create-replica-and-allocate-resources-when-doing-composition/22115/1 "2025-03-24T03:08:12Z")

</div>

Here’s the [official example code](https://docs.ray.io/en/releases-2.43.0/serve/model_composition.html#deploy-compositions-of-models) demonstrating deployment composition

```auto
# File name: hello.py
from ray import serve
from ray.serve.handle import DeploymentHandle

@serve.deployment
class LanguageClassifer:
    def __init__ (
        self, spanish_responder: DeploymentHandle, french_responder: DeploymentHandle
    ):
        self.spanish_responder = spanish_responder
        self.french_responder = french_responder

    async def __call__ (self, http_request):
        request = await http_request.json()
        language, name = request["language"], request["name"]

        if language == "spanish":
            response = self.spanish_responder.say_hello.remote(name)
        elif language == "french":
            response = self.french_responder.say_hello.remote(name)
        else:
            return "Please try again."

        return await response

@serve.deployment
class SpanishResponder:
    def say_hello(self, name: str):
        return f"Hola {name}"

@serve.deployment
class FrenchResponder:
    def say_hello(self, name: str):
        return f"Bonjour {name}"

spanish_responder = SpanishResponder.bind()
french_responder = FrenchResponder.bind()
language_classifier = LanguageClassifer.bind(spanish_responder, french_responder)

```

Do `num_replica` and `ray_actor_options` of a deployment affect the number of replica and resources of those deployments being referred to?  
In other words, does the setting specified in `serve.deployment` affect only the decorated deployment, or it also recursively applies to the deployments it uses?

---

<div class="post-metadata">

**Author:** ![alexyang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/alexyang/32/7512_2.png) [@alexyang](https://discuss.ray.io/u/alexyang)\
**Post date:** [March 24, 2025, 10:19pm UTC](https://discuss.ray.io/t/how-does-serve-create-replica-and-allocate-resources-when-doing-composition/22115/2 "2025-03-24T22:19:31Z")

</div>

Hi @mk6, thanks for posting to the community. The configurable parameters in `@serve.deployment` do not apply recursively to the child deployments that are referenced. This allows each deployment to scale up/down independently.
