Skip to main content

Lnt Mindtree part2

 1)Elastic search and graph ql explain?:

GraphQL and Elasticsearch are two distinct technologies that serve different purposes but can be complementary in building modern applications, especially those involving data querying and retrieval.


GraphQL:

GraphQL is a query language for APIs and a runtime for executing those queries by using a type system you define for your data. It was developed by Facebook and later open-sourced. The key features of GraphQL include:


Flexible Querying: With GraphQL, clients can request only the data they need, allowing them to specify exactly which fields they want to retrieve from the server. This helps in reducing over-fetching and under-fetching of data.


Strong Typing: GraphQL APIs are strongly typed, meaning you define a schema that outlines the types of data available and the relationships between them. This schema serves as a contract between the client and server.


Single Endpoint: GraphQL APIs typically expose a single endpoint for all data operations. Clients send queries or mutations to this endpoint, specifying the data they want, and receive a JSON response with exactly that data.


Real-time Updates: GraphQL subscriptions enable real-time data updates by allowing clients to subscribe to specific events and receive updates whenever those events occur.


Elasticsearch:

Elasticsearch is a distributed, RESTful search and analytics engine built on top of Apache Lucene. It's commonly used for full-text search, log analytics, and as a data store for structured and unstructured data. Key features of Elasticsearch include:


Full-text Search: Elasticsearch provides powerful full-text search capabilities, including support for fuzzy matching, stemming, and relevance scoring. It's commonly used in applications where users need to search through large volumes of textual data.


Distributed and Scalable: Elasticsearch is designed to be distributed and scalable, allowing you to easily add or remove nodes to handle changes in workload or data volume.


Near Real-time Indexing: Elasticsearch indexes data in near real-time, meaning that data is available for search shortly after it's indexed. This makes it suitable for applications that require fast data ingestion and querying.


Aggregations and Analytics: Elasticsearch supports aggregations, which allow you to perform analytics on your data, such as calculating sums, averages, or histograms across large datasets.


While GraphQL and Elasticsearch serve different purposes, they can be used together in a single application. For example, you could use GraphQL as the API layer to expose data to clients, and use Elasticsearch as the data store for querying and retrieving that data. This combination can provide a flexible and efficient way to build data-driven applications with rich querying capabilities.

2)

CDN (Content Delivery Network):

A Content Delivery Network (CDN) is a distributed network of servers located in multiple data centers across various geographic locations. The primary purpose of a CDN is to deliver web content to users with high performance, low latency, and high availability. Here's how it works:

  1. Caching: CDNs cache static content like images, CSS files, JavaScript, and videos in multiple edge servers located closer to end-users. When a user requests content, the CDN serves it from the nearest edge server, reducing the distance the data needs to travel and improving page load times.

  2. Load Balancing: CDNs use load balancing algorithms to distribute incoming traffic across multiple servers, preventing any single server from becoming overwhelmed with requests.

  3. DDoS Mitigation: CDNs often provide protection against Distributed Denial of Service (DDoS) attacks by absorbing and filtering malicious traffic before it reaches the origin server.

  4. Security: CDNs can provide SSL/TLS termination, encryption, and other security features to protect data in transit.

Popular CDN providers include Cloudflare, Amazon CloudFront, Akamai, and Fastly.

3)Enumerable:

Enumerable in js

ChatGPT

In JavaScript, properties of objects have an enumerable attribute, which determines if they will be iterated over by certain operations such as for...in loops and Object.keys().


When you create properties using a simple assignment (object.property = value), those properties are enumerable by default. However, certain built-in methods like Object.defineProperty() allow you to define properties with different attributes, including enumerability.


Here's how enumerability works in JavaScript:


Enumerable Properties:

By default, properties added using the dot notation or square bracket notation are enumerable.


javascript

Copy code

const obj = {

  name: 'John',

  age: 30

};


for (const key in obj) {

  console.log(key); // Output: "name", "age"

}


console.log(Object.keys(obj)); // Output: ["name", "age"]

In this example, both name and age properties are enumerable, so they are iterated over in the for...in loop and included in the array returned by Object.keys().


Non-enumerable Properties:

You can create non-enumerable properties using Object.defineProperty() or Object.defineProperties() methods.


javascript

Copy code

const obj = {};


Object.defineProperty(obj, 'name', {

  value: 'John',

  enumerable: false

});


for (const key in obj) {

  console.log(key); // Output: Nothing will be logged

}


console.log(Object.keys(obj)); // Output: []

In this example, the name property is defined as non-enumerable, so it won't be iterated over in the for...in loop and won't be included in the array returned by Object.keys().


Enumerability Control:

You can control the enumerability of properties when defining or modifying them using Object.defineProperty().


javascript

Copy code

const obj = {

  name: 'John',

  age: 30

};


Object.defineProperty(obj, 'age', {

  enumerable: false

});


for (const key in obj) {

  console.log(key); // Output: "name"

}


console.log(Object.keys(obj)); // Output: ["name"]

In this example, the age property is made non-enumerable after it's been defined. As a result, it's not iterated over in the for...in loop and not included in the array returned by Object.keys().


Understanding enumerability in JavaScript is important for controlling how properties are iterated over and accessed in various operations.




4)Sharding:

Sharding in MongoDB is a method for distributing data across multiple machines to support horizontal scaling of database systems. It allows MongoDB deployments to handle larger data sets and provide higher throughput by distributing data across multiple servers.


Here's an example use case for sharding in MongoDB:


E-commerce Website:

Consider an e-commerce website that stores product data in a MongoDB database. As the website grows and the number of products increases, the size of the product database also grows, leading to performance challenges such as slower query response times and increased disk usage.


Problem:

The product database has become too large to fit on a single server.

Query performance is degrading as the dataset grows.

Disk space is running out on the single server.

Solution:

Implement sharding to horizontally scale the product database across multiple servers. Here's how sharding can be applied to the e-commerce website's MongoDB deployment:


Identify Key for Sharding: Determine a key based on which the data will be partitioned across multiple shards. In the case of an e-commerce website, a good candidate for the shard key could be product category or product ID.


Shard Cluster Setup: Set up a MongoDB cluster with multiple shards. Each shard is a separate MongoDB replica set, consisting of one or more servers.


Enable Sharding: Enable sharding on the database that holds the product data.


Shard Key Selection: Choose the shard key based on the identified key for sharding. In our example, let's choose product category as the shard key.


Data Distribution: As new products are added to the database, MongoDB automatically distributes them across different shards based on the shard key (product category). This ensures that products within the same category are stored together on the same shard.


Query Routing: When querying for products, MongoDB's query router (mongos) routes queries to the appropriate shard based on the shard key. This ensures that queries targeting specific product categories are efficiently routed to the appropriate shard.


Benefits:

Improved Query Performance: By distributing data across multiple shards, query performance improves as each shard only needs to handle a subset of the total data.

Horizontal Scalability: As the number of products grows, additional shards can be added to the cluster to handle increased load.

Fault Tolerance: MongoDB replica sets provide data redundancy and high availability, ensuring that the system remains operational even if individual servers or entire shards fail.

In summary, sharding in MongoDB enables the e-commerce website to scale its product database horizontally, ensuring optimal performance, scalability, and fault tolerance as the business grows.









Comments

Popular posts from this blog

Node.js: Extract text from image using Tesseract.

In this article, we will see how to extract text from images using Tesseract . So let's start with this use-case, Suppose you have 300 screenshot images in your mobile which has an email attribute that you need for some reason like growing your network or for email marketing. To get an email from all these images manually into CSV or excel will take a lot of time. So now we will check how to automate this thing. First, you need to install Tesseract OCR( An optical character recognition engine ) pre-built binary package for a particular OS. I have tested it for Windows 10. For Windows 10, you can install  it from here. For other OS you make check  this link. So once you install Tesseract from windows setup, you also need to set path variable probably, 'C:\Program Files\Tesseract-OCR' to access it from any location. Then you need to install textract library from npm. To read the path of these 300 images we can select all images and can rename it to som...

Globant part 1

 1)call,apply,bind example? Ans: a. call Method: The call method is used to call a function with a given this value and arguments provided individually. Javascript code: function greet(name) {   console.log(`Hello, ${name}! I am ${this.role}.`); } const person = {   role: 'developer' }; greet.call(person, 'Alice'); // Output: Hello, Alice! I am developer. In this example, call invokes the greet function with person as the this value and passes 'Alice' as an argument. b. apply Method: The apply method is similar to call, but it accepts arguments as an array. Javascript code: function introduce(language1, language2) {   console.log(`I can code in ${language1} and ${language2}. I am ${this.name}.`); } const coder = {   name: 'Bob' }; introduce.apply(coder, ['JavaScript', 'Python']); // Output: I can code in JavaScript and Python. I am Bob. Here, apply is used to invoke introduce with coder as this and an array ['JavaScript', 'Pyt...

Globlant part 2

 1)JWT token:           const jwt = require ( 'jsonwebtoken' ); A JWT token consists of three parts separated by dots ( . ): Header : Contains metadata about the type of token and the hashing algorithm used. Payload (Claims) : Contains the claims or statements about the subject of the token, such as user ID, roles, etc. Signature : Verifies that the sender of the JWT is who it says it is and ensures that the message wasn't changed along the way. It is header +payload +secret key. Methods: const newToken = jwt. sign (payload, secretKey, { expiresIn : '1h' }); Use verify() when you need to ensure the token's integrity and authenticity. Use decode() when you only need to extract information from the token and don't need to verify its signature. 2)Window ,this,global: In nodejs this and global refers to same global methods and varibales just that no dom related things that are in window. In nodejs no window. 3)a.getSum(); // Define the custom method getSu...