Senior Software Engineer
Kreeti Technologies Pvt. Ltd.
AWS S3
Jira

Sentry

InVision
Figma
.png)
Docker
So yeah. Hi. I'm Sachin Kumar Gupta. I'm a senior software engineer at, uh, Technology Private Limited. I've been working in this company for the last, uh, 6 years more than 6 years. And, uh, my me primary stack, which I'm working on is Ruby on Reels and React developer. So, yeah, that's all.
So to refactor a complex, uh, view template, what we will have to do is, uh, we'll have to identify the components, the parcels that can be created. So that will be the main thing. Uh, so first thing first, you'll have to add test so that we can make sure that viewed, uh, in reels, we can add view test. So if the team follows that convincing, you can add test for the view. And then, uh, and then what you can do is, uh, you will have to identify the per seals which can be created, common components which can be created. And, uh, yeah, based on that, we'll have to refactor. Actually, yes, that's all. Let me think. So yeah. Uh, parcels are one way to go, like, uh, creating common creating parcels and making them do specific task. Like, it's yeah. That's one way to go. Then you can also use helper functions. So view related helper functions can be used where the, uh, view logics can be placed. That is another way way of, uh, bringing clarity, uh, to the component.
So, uh, yep. So in the React front end when, uh, with Reels back end, What we have to do is we will have to use, um, if the application is if the application is complex and require global state management, then we'll introduce, uh, we'll use some globally, uh, uh, state management libraries like Redux. Then then, uh, Redux. And along with that, Redux also provide Redux toolkit and all. So using that, we can, uh, like, whatever data we consume from the API, we can assure them in the Redux. So yeah. And then you you when we'll have to use x library like Axios, uh, for gracefully handling, uh, errors and, uh, for retrying and all. What else can be done? Let me think. So, uh, if the reels API following this will practice okay. Okay. So, uh, we can also, uh, have the documentation about how the reels, um, is sending the response. So that will become a key point when designing the React front end for consuming the reels API. So if rails, EPA follows pattern like JSON API and all, then in front end also, you can have, uh, you can write, uh, reducts in a way that consuming the data becomes easier. You can have a global seed global object where all the data go, and in your individual Redux, uh, you can only just keep the IDs. So in that way also, you can go. So, yeah, that is
So Rails allows to connect to multiple databases. So that concept can be used, uh, for, um, one approach will be, like, having separate databases altogether. So for different, uh, tenants, for different phones, different organizations, we can have different, um, databases. Uh, from security point of view, that will be the best. But if we are going with a single database, um, that will have, uh, in terms of complexity, that will be less complex. So that will be the benefit of having a single database. And in that case, uh, what we can do is, uh, in one of the application, what we did is, uh, in the URL segment itself, we appended the subdomain part. So let's say if the company name is abc.com and the tenant name is x, then we'll have x.abc.com. And using this x, we can identify the tenant. Um, using the subdomain, we can identify the, uh, tenant, and then whatever calls, whatever API calls which are make being made. Okay? If any API call is being made from this, uh, x.abc.com, then we'll scope all the API calls which we are going to execute up against our database, uh, for that tenant. Okay. So by default, that scope will be applied. Okay. So in that way, what will happen is, uh, we'll have, uh, miss we'll we can make sure that, uh, there's no, uh, data or security risks, uh, involved.
Okay. So to optimize, what we can do is, one is from the application side, we can reduce n plus one queries. Okay. The other thing means n plus one queries we'll have to find out, uh, using gems like bullet or, uh, rake, uh, mini profiler and, uh, resolve those things. Then in the back end, uh, we'll have to use index on the right, uh, attributes of the table so so that, uh, our query time increases, uh, is becomes, um, good. Now, uh, the other thing is profiling, knowing which data is causing problem, uh, which query is taking more time, and finding a better solution for that. So some databases like Postgres provide has some features of its own, which can be used to, uh, which can it provides some operation which are not provided in other databases. So, uh, database specific feature could be used, if possible, to optimize the query, or some queries are written in, uh, not in a good way. So, uh, we can optimize here also. So adding index, reducing n plus 1 queries, uh, and then optimizing the queries, what else can be done? Yes. The other thing is caching, uh, but that okay. Caching of frequently and static, uh, data that can be done within the application so that we don't reach out to the SQL within the application so that we don't reach out to the SQL server. So casing can be used to improve. And then we can use data sorting also.
I don't understand the question. Like, I don't understand why, uh, uh, someone would like to have a statefulness in a customer facing Rails application. Uh, stateless application makes sense. Uh, statefulness, the reason could be, like, you only have one server, and then, yeah, you in one of the application, we did I did this, uh, but are there very specific reasons for doing this? Uh, so some effective strategy. So, basically, for doing this, what we'll have to do is we'll have to use some, uh, this whatever variable we need to define. Whatever is saved, we need to define. We'll have to define that in other global folder. Maybe, uh, say, uh, some will have to define the model with some in the base model or, um, maybe in the in the controller base controller in the initializer file or, anyway, we'll have to define those, uh, state states and then use it.
So, basically, this serve this code, um, executes the service dot it calls the service dot execute function. And if there is any error of type service colon colon service error, then it caches out that error and, uh, an error message is soon. If there are error of some other kind, then this will also catch all the errors. All other errors will be caught. And in the in the next block, it catches all the errors and just shows all these errors, and then it raises the same error. Then it again raise the error. So when it's raising the error, it's not passing the error object, just saying raise. So that can create a issue.
So in this code, we are trying to fire you we are trying to make sure that, uh, new and create accent can only be called if the user is admin user. And that index new and create is is can, uh, whenever a request is made for in the, uh, any action except index new and create, uh, will run a code that, uh, instantiate the user record. So it instantiates the current user. No. No. The problem with this code is that, uh, except for new and create, Means in case of new and create, it's not trying to find the user. It's not assigning who the user is, which should be called. So current user finding the current users will be done before, um, checking whether the user is current user or not. Also, we are using current user dot add in, whereas we are finding, uh, find user at the rate user equals user dot find. So we are doing that. So, uh, when we are finding the user, user findings should be done before, and it should be done for new and create both because new and create depends on whether the user is currently uh, whether the current user is admin or not. So if you don't have the user record, we'll not be able to identify whether that's the case or not.
First of all, acid stands for a stands for atomic, c for consistency, I for isolation, and d for durability. So atomic says that either, um, atomic says that either the entire operation should complete or the entire operation should roll back. It should happen as a single unit. Consistency says that, uh, before they see it before the the transaction is started and they seed, uh, after the transaction, um, after the transaction ends, should be, uh, consistent. So say if a transfers 50 rupees of b, he was having a 100 rupees and b was having 50 rupees, and he said, uh, 50 rupees initially, then total is 1.50. Then at the end of the transaction also, uh, this total amount should be 1.50 only. It should not happen that the money got deducted from a account. And now a has 50 rupees, and b also has 50 rupees, and so the total amount is 100. That should not happen. So that violates see. Isolation, um, means, uh, each of the transaction, uh, should happen as if there's no other transaction. This will not be aware of any other transaction happening. Okay? Uh, this would be completely isolated as if, uh, as if they are happening, uh, in an isolated moment, and, uh, uh, and and, uh, let's see. Had other transaction not occurred, the result of this and if if this transaction would have occurred when other transaction are happening, then both the result would does not get affected. So not knowing isolation says that, uh, other transit and presence of other, uh, transactions would, uh, not affect or should not, um, it should be isolated. Transactions would be isolated, completely isolated. Durability. So, uh, it says that whenever there's, uh, things like a power failure or something, uh, new applications should still be able to function. Okay. Uh, so those things should happen. Sorry. And that is the thing, maintain as if compliance. What isolation level do you consider when handling transaction? The application to one is maintain a safe compliance. So, yeah, that is all.
So Lambda can be used to move certain part of the application, certain features of the application, uh, to AWS Lambda. We can move those things. So, uh, let's say, uh, we are building an email tracking feature, and we want to move we then in that case, whenever in SQS event is triggered, either we can, um, whenever in a email is sent, what we can do is, uh, SMS is triggered. And after SMS is triggered, we can the application can receive the, uh, receive this event and process it, or it can send it to SQS, and SQS can send it to for, uh, to Lambda. And in that way, they can, uh, have Lambda consume it. Okay. So and and so what will happen is your server is not handling the those functionality. The Lambda is basically function as a service. So anything which can be moved any function which can be moved to AWS services, uh, AWS Lambda services, and we want the scalability, we should do that. And in that way, we'll be able to improve our our app performance. One other thing could be processing a file and generating the thumbnail and all once the file is uploaded. So that can go to the server, but instead, we can go for a direct upload using a pre signed URL and all. And then once the, uh, once something is uploaded in a certain back bucket, we can, uh, add a trigger that a certain Lambda will will get executed, and, um, that will process and generate the required thumbnails and required pictures of differences.
So real time communication can be done. Uh, so for real time, we, uh, we go for, um, this WebSocket. In Rails, we already have accent cable, which provides the same functionality under the hood uses WebSocket, but, um, so using WebSocket, we can, uh, like, achieve this. We'll have to define subscriber, publisher, channels to which, uh, the reels front end app reels application will have to subscribe, and whenever something is published with that channel, uh, it will receive it, and in the front end, uh, we'll get it. So, yeah, not much change will be required.