# Microservices architecture implementaiton

**URL:** <https://community.temporal.io/t/microservices-architecture-implementaiton/6376>\
**Category:** Community Support\
**Tags:** python-sdk\
**Created:** [November 1, 2022, 1:40pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376 "2022-11-01T13:40:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![niro](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/niro/32/2913_2.png) [@niro](https://community.temporal.io/u/niro)\
**Post date:** [November 1, 2022, 1:40pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/1 "2022-11-01T13:40:30Z")

</div>

Hi,  
I have a current micro-srv implementation decoupled by RabbitMq and I want to move to Temporal implementation.  
My tech stack is Python and Node currently deployed to a different kind of OS (docker images).  
What is not very clear to me is how to register each activity (or several) to different microservices using the Python or Node SDK, without decoupling the code between services (library etc.)  
I tried to follow this thread ([springboot-microservices](https://community.temporal.io/t/springboot-microservices-managed-by-temporal-io-rabbitmq/1489/7)) , which seems to try achieving the same goal, but in the end I couldn’t implement it in python or node (maybe because the java api is a bit different).

So for example, here is a very simple workflow:

```auto
@workflow.defn
class SayHello:
    @workflow.run
    async def run(self, name: str) -> str:
        hi = await workflow.execute_activity(
            "say_hello", name, schedule_to_close_timeout=timedelta(seconds=5)
        )
        by = await workflow.execute_activity(
            "say_by", name, schedule_to_close_timeout=timedelta(seconds=5)
        )
        return hi + by

```

And these are the activities:

```auto
@activity.defn
async def say_hello(name: str) -> str:
    # I will run on linux server
    return f"Hello, {name}!"

@activity.defn
async def say_by(name: str) -> str:
    # I will run on Unix server
    return f"Byby, {name}!"

```

So, if I understand correctly I should have in each service a worker that handle different activity:

```auto
client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="my-task-queue",
        workflows=[SayHello],
        activities=[say_hello],
    )
    await worker.run()

```

But when I run it I get the following error:

> Activity function say\_by is not registered on this worker, available activities: say\_hello …

I guess there should be a service that runs only the workflow regardless of the activities (same as the diagram below) what am I missing? will be glad to get directions and the right way to implement it.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/4/4a0cac459c37420f4defa49522c8f51f7c6f0f64.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [November 1, 2022, 1:54pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/2 "2022-11-01T13:54:25Z")

</div>

> [@niro](#):
>
> So, if I understand correctly I should have in each service a worker that handle different activity:

Not exactly. Workers should include _all_ workflows/activities that task queue can handle. If you want different activities to run in different workers, you should use different task queues on different workers. Then explicitly set the task queues on `execute_activity` when you invoke the activity.

---

<div class="post-metadata">

**Author:** ![niro](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/niro/32/2913_2.png) [@niro](https://community.temporal.io/u/niro)\
**Post date:** [November 1, 2022, 2:00pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/3 "2022-11-01T14:00:17Z")

</div>

Something like this:

Workflow worker:

```auto
@workflow.defn
class SayHello:
    @workflow.run
    async def run(self, name: str) -> str:
        # using string as activity name to avoid decoupling
        hi = await workflow.execute_activity(
            "say_hello",
            name,
            task_queue="say-hi-task-queue",
            schedule_to_close_timeout=timedelta(seconds=105),
        )
        # using string as activity name to avoid decoupling
        by = await workflow.execute_activity(
            "say_by",
            name,
            task_queue="say-by-task-queue",
            schedule_to_close_timeout=timedelta(seconds=105),
        )
        return hi + by

async def main():
    # Create client connected to server at the given address
    client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="my-workflow-queue",
        workflows=[SayHello],
        activities=[],
    )
    await worker.run()

```

Activity worker:

````auto

@activity.defn
async def say_hello(name: str) -> str:
    # I will run on linux server
    print("Hello")
    return f"Hello, {name}!"

async def main():
    # Create client connected to server at the given address
    client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="say-hi-task-queue",
        workflows=[SayHello],
        activities=[say_hello],
    )
    await worker.run()```
````

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [November 1, 2022, 2:09pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/4 "2022-11-01T14:09:42Z")

</div>

Mostly, yes. There is a bit of a bug where you execute the workflow on `my-workflow-queue` but your putting the workflow on `say-hi-task-queue`. You can choose whether you want to combine the workflows and activities on a task queue or not. But you need to make sure that the worker task queue you put the workflows/activities on is the task queue you are setting when you invoke the workflows/activities.

---

<div class="post-metadata">

**Author:** ![niro](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/niro/32/2913_2.png) [@niro](https://community.temporal.io/u/niro)\
**Post date:** [November 1, 2022, 2:41pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/5 "2022-11-01T14:41:49Z")

</div>

> [@Chad\_Retz](#):
>
> workflow

can you explain why it’s a bug?  
The workflow is running on a queue and each activity run on a different queue.  
this is the client that start the workflow:

```auto
client = await Client.connect("localhost:7233")

    # Execute a workflow
    result = await client.start_workflow(
        "SayHello", "my name", id="my-workflow-id-1", task_queue="my-workflow-queue"
    )

```

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [November 1, 2022, 4:42pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/6 "2022-11-01T16:42:44Z")

</div>

> [@niro](#):
>
> The workflow is running on a queue and each activity run on a different queue.

But this says a workflow and activity are running on the same queue:

> [@niro](#):
>
> ```auto
> worker = Worker(
> client,
> task_queue="say-hi-task-queue",
> workflows=[SayHello],
> activities=[say_hello],
> )
> 
> ```

Leave `workflows=` off of there if you don’t want workflows on that task queue

---

<div class="post-metadata">

**Author:** ![niro](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/niro/32/2913_2.png) [@niro](https://community.temporal.io/u/niro)\
**Post date:** [November 1, 2022, 4:58pm UTC](https://community.temporal.io/t/microservices-architecture-implementaiton/6376/7 "2022-11-01T16:58:30Z")

</div>

Got it … 10X a lot
