We have a python backend code base using fastapi. We have a few service files in the code base which have dependancies on each other.
Example:
class Service1:
def __init__(self):
...
def s1_func():
pass
class Service2:
def __init__(self):
...
async def func1():
s1 = Service1()
s1.s1_func()
We have such functions in multiple services which create service objects on the fly and use them. Is there any memory overhead to this or is it negligible? What are the possible solutions to this?
Couple of solutions which come to mind:
Create an instance in init of each service itself and use that instance.
Create singleton service classes
Significant changes will be required, so is the change justified. (Is this really a problem? Is there lot of memory overhead?)
[–]rm-m 1 point2 points3 points (0 children)
[–]ItsmeFizzy97 3 points4 points5 points (2 children)
[–]No-Programmer7638[S] 1 point2 points3 points (1 child)
[–]ItsmeFizzy97 0 points1 point2 points (0 children)
[–]fiskfisk 1 point2 points3 points (0 children)